How to write SQL statements by searching records of Table A without data in Table B

Source: Internet
Author: User
How do I write SQL statements when I search for records in Table A that have no data in Table B? For example, a_id & nbsp; name & nbsp; & nbsp ;........ & nbsp; 1 & nbsp; how do I write SQL statements for records in Table B without data in table?
For example:
Table
A_id name ........
1 Zhang San
2 Li Si
3. Wang Wu
4 Zhao Liu


Table B
B _id a_id total
1 100
2 3 200


How can I find Li Si and Zhao Liu after I select the overdue payment submission option above ????
------ Solution --------------------
Because Wang Wu has made a payment and has not yet owed a loan, he does not need to submit a ticket.
The primary account should be used to find out the accounts that have not been handed in or have overdue payments.

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 perform this operation by left join first, and then find the records with qianfei> 0 or qianfei being 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.