SQL兩張表篩選相同數據和不同數據


原文鏈接:http://www.cnblogs.com/onesmail/p/6148979.html

方法一:

 select distinct A.ID from  A where A.ID not in (select ID from B)

方法二:

select A.ID from A left join B on A.ID=B.ID where B.ID is null

方法三:

select * from  B  where (select count(1) as num from A where A.ID = B.ID) = 0

方法四:

SELECT * FROM b WHERE NOT EXISTS(SELECT 1 FROM a WHERE tel_no=b.tel_no)

 

方法五:

--相同數據
select tel_no  
from a
intersect
select tel_no 
from b

--不同數據
select tel_no  
from b
except
select tel_no 
from a


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM