比如A1表 100W行 A2表50W行
select a.* from A1 a where a.column1 in (select b.column1 from A2 b where b.column2='xxx');
select a.* from A1 a where exists (select 'x' from A2 b where b.column2=xxx and a.column1=b.column1);
select a.* from A1 a,A2 b where b.column2='xxx' and a.column1=b.column1
在(select b.column from A2 b where b.column2=xxx)的結果集比較小的情況下(比如只有幾十條)用in的效率高於關聯,
如果結果集比較大的情況下則用join的效率高於用
in,
這里我還列舉了exists,這個效率類似於join也是結果集大的情況下適用,至於兩者的拐點還需要你在執行計划和統計信息當中去觀察以便確定出最優的sql語句。