比如 a,b 关联列为 a.id = b.id,现在要取 a 中的数据,其中id在b中也存在:
select * from a where exists(select 1 from b where a.id = b.id)
或者:
现在要取 a 中的数据,其中id在b中 不存在:
select * from a where not exists(select 1 from b where a.id = b.id)
例如:表B:
表C:
select * from B where not exists (select 1 from C where B.ID=C.ID)
结果:
select * from B where exists (select 1 from C where B.ID=C.ID)
结果: