日期:2014-05-18  浏览次数:20508 次

如何查询在A表中不存在的B表的数据(id+bm两个条件)

A 表

id bm
1 2
1 3
1 4



b表
id bm
1 2
1 3
1 4
1 5
1 6

如何查询在A表中不存在的B表的数据(id+bm两个条件)

如图的话就是

1 5
1 6





------解决方案--------------------
SQL code
select b.*
from b
where not exists(select 1 from a where a.id=b.id and a.bm=b.bm)

------解决方案--------------------
SQL code
select * from a where not exists(select 1 from tb where id=a.id and bm=a.bm)

------解决方案--------------------
SQL code
select * from b except select * from a

------解决方案--------------------
select * from A where checksum(id, bm) not in (select checksum(id, bm)from B)
------解决方案--------------------
SQL code

select * from B
WHERE NOT EXISTS (SELECT 1 FROM A WHERE id = B.id AND bm = B.bm)

------解决方案--------------------
SQL code
select * from a where checksum(*) not in(select checksum(*) from b)