读书人

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

发布时间: 2012-04-18 15:01:59 作者: rapoo

求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)

读书人网 >SQL Server

热点推荐