Query A, B table, a table in the existence of table B does not exist data

Source: Internet
Author: User

Go A, b two tables, find the ID field, there is a table, but there is no data in table B. A total of 13w data, after the deduplication of about 3W data, b table has 2W data, and B table ID field is indexed.

Method One

Use not in, easy to understand, low efficiency ~ Execution Time: 1.395 seconds ~ (the first method of pro-test is available)

1Selectdistinct a.id from A where a.id not in  (select ID from B)      
Method Two

Use left Join...on ..., "b.id isnull" indicates a record of NULL in the b.ID field after you have connected-the execution time: 0.739 seconds ~

1Select a.IDFrom Aleft join B  On a.ID = b.ID where b.ID is null 

Graphic

Method Three

Logic is relatively complex, but the fastest ~ execution time: 0.570 seconds ~ (feeling this way is very good)

1 from   B 

2Where (SelectCount 1) as num from A where a.id = b.id) = 0

(turn) query A, B table, a table in the existence of table B does not exist data

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.