1.exist,not exist一般都是与子查询一起使用. In可以与子查询一起使用,也可以直接in (a,b.....)
2.exist会针对子查询的表使用索引. not exist会对主子查询都会使用索引. in与子查询一起使用的时候,只能针对主查询使用索引. not in则不会使用任何索引. 注意,一直以来认为exists比in效率高的说法是不准确的。
区别:
1.性能的考虑此时就按子表大主表小用exist,子表小主表大用in的原则就可以.
2.写法的不同, exist的where条件是: "...... where exist (..... where a.id=b.id)"
in的where条件是: " ...... where id in ( select id .... where a.id=b.id)"