Oracle SQL 中的IN & EXISTS 比较

2014-11-24 17:52:36 · 作者: · 浏览: 1

select * from t1 where exists ( select null from t2 where y = x )
执行的过程相当于:
for x in ( select * from t1 )
loop
if ( exists ( select null from t2 where y = x.x )
then
OUTPUT THE RECORD
end if
end loop

表 T1 不可避免的要被完全扫描一遍


分别适用在什么情况
以子查询 ( select y from T2 )为考虑方向
如果子查询的结果集很大需要消耗很多时间,但是T1比较小执行( select null from t2 where y = x.x )非常快,那么exists就比较适合用在这里
相对应得子查询的结果集比较小的时候就应该使用in.

2 含义上的比较
在标准的scott/tiger用户下