1)in的逻辑规则是or not in 的逻辑规则是 and
2)判断null 的sql语句为 is not null 或者 is null
3)当遇到 null = null 的判断是时由于不符合null的判断规则,所以结果一定为flase
-
not in 中包含null值的情况
select *
from A
where A.name not in
(select B.name
from B )
在上面的not in的查询中如果B表的name字段存在空值时,不论何种情况上述语句的查询结果一定为空
- in 中包含null值的情况
select *
from A
where A.name in
(select B.name
from B )
在上面的 in 的查询中如果B表的name字段存在空值时,如果A表中存在name字段也存在空值,那么上述语句的查询结果中不会显示A表中的空值
1)in的逻辑规则是or not in 的逻辑规则是 and2)判断null 的sql语句为 is not null 或者 is null3)当遇到 null = null 的判断是时由于不符合null的判断规则,所以结果一定为flasenot in 中包含null值的情况select * from A where A.name not in (select B.name from B )在上面的not in的查询中如果B表的name字段.
前一段时间在公司做一个小功能的时候,统计一下某种情况下有多少条数据,然后修改的问题,当时感觉很简单,写了一个如下的 SQL:
SELECT COUNT(*) FROM t1 where tl.c1 not IN (SELECT t2.c1 FROM t2);
预期的结果是:有多少条数据在 t1 中,同时不在 t2 中,结果为:0,也就是 t1 中数据都在 t2 中,但是很容易就发现某些数据在 t1 中不在 t2 中,所以就感觉很奇怪,这个 SQL 看着也没问题啊。经过一番查询原来是因为 t2 的 c1 字段包含了 null 值,修改如下两种形式都可以得到预期的结果:
SELECT COUN
select * from emp e where e.comm in (300, 500, null);
2. 使用not in的时候,如果 not in后面的选项中没有null,只会查询从comm列不为空的列中过滤,会过滤掉comm为null的数据
select * from emp e where e.comm not in (300, 500);
3.使用not in 的时候,如.
作者:吴晓佩
撰写时间:2019年4月6日
上次我在子查询中用多行操作符(not in)进行数据查询时出现过此种情况,数据是空的,为了验证一下结果,我用in 查询了该表的数据,发现查询出来的结果数据并没有等于该表的总数据,所以not in一定是会存在数据的,然而数据竟然是null。
原因是条件中存在一个空值,...
insert into test_in(name, hobby, sex, school) values('张一','打球',1,'北京大学');
insert into test_in(name, hobby, sex, school) values('张二','看书',null,'清华大学');
insert into test_in(name, hobby, sex, school) values('张三','游泳',1,null);
insert
insert into tmp_1 (bb) values('1');
insert into tmp_1 (aa) values('1');
insert into tmp_1 (aa) values('2');
insert into t
用in的时候一般问题不大,使用not in的时候需要特别主要,结合本文恰当使用,之所以
造成如此大的差异原因是对NULL的判断上,NULL的判断本质上is null或is not null,in或
not in的判断是等于(=),所以对NULL判断是无效的,需要谨记。.........
SQL> select * from v$version;
BANNER
----------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production