Search for a table in B tables no data records how to write SQL statements

Source: Internet
Author: User
How to write SQL statements when searching for a record with no data in table B?
Such as:
Table A
a_id name .....
1 sheets of three
2 John Doe
3 Harry
4 Zhao Liu


b table
b_id a_id Total
1 1 100
2 3 200


Check the above arrears after submission how to search out John Doe and Zhao Liu????
------Solution--------------------
It is not necessary to show that Harry is paying for it and is not being wasted.
The owner should be looking for a customer who is not paying or has

Select T1.name from a as T1 left join B as T2 on t1.a_id=t2.a_id where Qianfei is null or qianfei>0;

You can write this, left join first, and then find qianfei>0 or Qianfei as null.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.