SQLServer两张表筛选相同数据和不同数据

来源:互联网 发布:英伟达优化软件 编辑:程序博客网 时间:2024/05/22 06:11
SQLServer两张表筛选相同数据和不同数据

方法一:

 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 aintersectselect tel_no from b--不同数据select tel_no  from bexceptselect tel_no from a
复制代码

 

阅读全文
0 0
原创粉丝点击