1) select * from T1 where exists(select * from T2 where T1.a=T2.a) ;
T1数据量小而T2数据量非常大时,T1<<T2 时,1) 的查询效率高。
2) select * from T1 where T1.a in (select T2.a from T2) ;
T1数据量非常大而T2数据量小时,T1>>T2 时,2) 的查询效率高。
in 是把外表和内表作hash 连接,而exists是对外表作loop循环,每次loop循环再对内表进行查询.
如果两个表中一个较小,一个是大表,则子查询表大的用exists,子查询表小的用in.
原文:http://www.cnblogs.com/moonandstar08/p/5052644.html