b表是a表的子集,现在要查询出(a-b),这个sql怎么写
------解决方案--------------------
试试这个:
select *
from a
where not exists(select 1 from b where a.id = b.id)
------解决方案--------------------
上面的主要是通过a和b表的关联字段来判断的。
如果是多个字段,那么可以改为:
select *
from a
where not exists(select 1 from b
where a.col1 = b.col1 and
a.col2 = b.col2 and
a.col3 = b.col3)