详细出处参考:http://www.jb51.net/article/11123.htm 使用EXISTS(或NOT EXISTS)通常将提高查询的效率,由于NOT IN子句将对子查询中的表执行了一个全表遍历。 oracle在执行IN子查询过程中,先执行子查询结果放入临时表再进行主查询; 而exists先运行主查询,再执行子查询查到第一个匹配项 如:查询 A表中没有和B表或C表相连的数据 select A.id,A.reads,A.addtime from A where A.person_id not in (select user_id from B ) or A.worksite_id not in (select id from C) order by A.addtime desc 程序执行时间:40109.38毫秒 select A.id,A.reads,A.addtime from A where not exists (select id FROM B where B.user_id=A.person_id) or not exists (select id FROM C where C.id=A.worksite_id) order by Sendorder.addtime desc 程序执行时间:8531.25毫秒 |
|
来自: 昵称16088576 > 《SQL笔记》