多个字段的in和not in用exists替换实现写法

表结构说明

表a  有字段:aaa,bbb,还可能有其余字段。spa

表b  有字段:aaa,bbb,还可能有其余字段。select

表a的字段aaa跟表b的字段aaa有对应关系,表a字段的bbb跟表b的字段bbb有对应关系。查询

 

in 换 exists

从表b里查询出知足条件“select aaa,bbb from a”的记录

select * from b where  exists ( select * from a where a.aaa=b.aaa and a.bbb=b.bbb);

 

not in 换 not exists

从表b里查询出不在结果集“select aaa,bbb from a”中的记录

select * from b where not exists ( select * from a where a.aaa=b.aaa and a.bbb=b.bbb);

相关文章
相关标签/搜索