oracle 子查询 嵌套查询 子查询用有null问题

通常情况下, 数据库中不要出现null,最好的做法加上非空约束Not null,null值并不代表不占空间, char(100) null占100个字符

 1     --查询不是领导的信息(含null值错误写法)
 2 
 3     select * from emp where empno not in (select mgr from emp); --查询不到记录
 4 
 5     select * from emp where empno <>all(select mgr from emp);--上行等价写法
 6 
 7  
 8 
 9     --查询不是领导的信息(含null值正确写法)
10 
11     select * from emp where empno not in (select mgr from emp where mgr is not null); --查询出8条记录

猜你喜欢

转载自www.cnblogs.com/smartisn/p/12179470.html