SQL语句 in和inner join各有什么优点

比如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语句。
原文地址:https://www.cnblogs.com/xbblogs/p/6116809.html