SQL queries-data that exists in one table and not in another

Source: Internet
Author: User
Tags one table

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

Easy to understand with not in, low efficiency ~ Execution Time: 1.395 seconds ~

Select distinct  from where  not inch (Select 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 ~

Select  from  Left Join  on a.ID=whereisnull

Method Three

Logic is relatively complex, but fastest ~ execution time: 0.570 seconds ~

Select *  from where (SelectCount(1as fromwhere==0 

SQL queries-data that exists in one table and not in another

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.