1、in 與 exists:
外表大,用IN;內表大,用EXISTS;
原理:
用in:外表使用了索引,直接作hash連接;
用exists:內表使用了索引,外表作loop循環再進行匹配;
2、not in與not exists:
性能:not in不走索引,所以一般都用not exists;
區別:還有一點區別就是,not in字段為null的不進行篩選出來;而使用not exists即可;
這也就是說有時定義字段,用not null比較好了,這樣也能避免not in查詢出錯。