首页 > 代码库 > SQL语句Not IN优化方案
SQL语句Not IN优化方案
总结网友们在CSDN社区上对于not in的优化策略,整理如下,备查。
select * from emp where emp_no not in (select emp_no from emp_bill)
要求用两种 SQL 写法优化上面 SQL 。
方法一、
select *
from emp a
where not exists ( select 1
from emp_bill b
where b.emp_no = a.emp_no)
方法二、
select a.*
from emp a ,emp_bill b
where a.emp_no=b.emp_no(+)
and b.emp_no is null
方法二继续优化、
select a.*
from emp a ,emp_bill b
where a.emp_no=b.emp_no(+)
and NVL(b.emp_no, ‘1‘) = ‘1‘
表连接效率最好, Not Exists 其次, Not in 最低
SQL语句Not IN优化方案
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。