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)"
