-
select * from A where id in (select id from B);等价于
select id from B;
select * from A where id in
in优先查询子表,再匹配外表。
2、select ... from table where exists (subquery);等价于
select ... from table where exists
subquery
exist优先查询外表,再查子表。
优化原则:数据量小的表驱动数据量大的表。
假设子表数据量大,外表数据量小。优先使用exist。
假设子表数据量小,外表数据量大。优先使用in。