一直聽到的都是說盡量用exists不要用in,因為exists只判斷存在而in需要對比值,所以exists比較快,但看了看網(wǎng)上的一些東西才發(fā)現(xiàn)根本不是這么回事。 下面這段是抄的 Select * from T1 where x in ( select y from T2 ) 執(zhí)行的過程相當于: select * from t1, ( select distinct y from t2 ) t2 where t1.x = t2.y;
select * from t1 where exists ( select null from t2 where y = x ) 執(zhí)行的過程相當于: 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