SQL has one table but not the data in another table. SQL is not

Source: Internet
Author: User

SQL has one table but not the data in another table. SQL is not

Select. id,. OA code,. custid,. custname,. xsz,. salename,. communicationtheme,. communicationproperty,. communicationtime,. productmanager, ''creator,. creator oaCreator,. createdate, case when. oastate = 'normal termination' then 3 else 0 end status from exception_flow a where (1 = 1) and (. oastate = 'normal termination' or. oastate = 'feedback 'or. oastate = 'feedback') and (select count (1) as num from policy_support s where s. OA code =. OA code) = 0


How to use an SQL statement to query the first record that exists in one table and does not exist in the other table?

Select top 1 *
From tb2
Where id not in (select [index] from tb1)
Order by id

SQL queries whether data in one table exists in another table

Insert into tableA
Select * from tableB B where not exists (select 1 from tableA a where a. id = B. id)
Insert into tableA
Select * from tableB B
Left join tableA a on a. id = B. id
Where a. id is null
---- Use not exists to judge, left join, where the condition is the unique primary key

Related Article

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.