Searches for records that exist in one table and do not exist in the other table.

Source: Internet
Author: User

For example, two tables: T1 and T2. query records that exist in Table T1 but do not exist in Table T2.

Assume that the ID field is used as the associated field.

Method 1: the fields of the two tables must be completely consistent.

Select *
From T1
Minus
Selecct * From T2

 

Method 2:

Select * from T1
Where not exists (select 1 from T2 where t1.id = t2.id)

 

Method 3:

Select * from T1
Where id not in (select ID from T2)

 

Method 4: t2.id cannot be blank

Select T1 .*
From T1
Left join T2 on t1.id = t2.id
Where t2.id is 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.