当前位置: 代码迷 >> Sql Server >> 求A表和B表的差集,该怎么处理
  详细解决方案

求A表和B表的差集,该怎么处理

热度:38   发布时间:2016-04-27 13:52:46.0
求A表和B表的差集
有A表和B表,表结构相同,
如:A表
A B C
1 1 河北
1 2 天津
。。。。。


B表
A B C
1 1 河北
1 2 天津
。。。。。

想求出B表比A表多出来的记录

------解决方案--------------------
SQL code
select * from B where not exists(select 1 from A where A.A=B.A and A.B=B.B and A.C=B.C)
------解决方案--------------------
select b.* from b where not exists(select 1 from a where a.a = b.a and a.b = b.b and a.c = b.c)
------解决方案--------------------
select b.* from b where not exists(select 1 from a where a.a = b.a and a.b = b.b and a.c = b.c)
  相关解决方案