oracle - “不在哪里” - 最简单的查询中的奇怪返回
问题描述
我正在碰壁如何解释这一点:
select * from (
select '123' id1 from dual
) src
where src.id1 not in (select id1 from table1)
;
没有给我行
select * from (
select '123' id1 from dual
) src
where src.id1 in (select id1 from table1)
;
也没有给我任何行。
在这两种情况下这怎么可能?
另一方面,如果不存在,则按预期工作。表 1 不为空。实际上,是的 - table1 既有空值也有非空值。为什么这会使相反的条件都错误?
编辑:不完全重复,因为列出的类似问题是为什么结果不同,而在这里 - 为什么在相反条件下结果相同 - 这可能会令人困惑。
解决方案
It looks like your list of ids to test against contains NULL
values.
Comparisons with NULL always return false. Even WHERE NULL = NULL
is false (same as WHERE NULL != NULL
). You'd need to use IS NULL
.
In your case, you probably want select id1 from table1 where id1 is not null
推荐阅读
- jquery - 如何在 slickgrid 中获取选定的列
- angular - 如何获得过滤数组的状态?
- java - 如何在项目反应器中组合来自两个反应流的数据?
- mysql - 为什么 SELECT 结果重复 4 次?
- python - 在预标记文本上使用 spacy
- linux - 在内核模块 module1.ko 之前加载依赖于 module1.ko 的内核模块 module2.ko
- python - 如何覆盖第三方 django 包的迁移
- react-native - 在 react-native 0.60 中找不到 RCTFont.h 文件
- google-apps-script - 复制行 Google 表格
- c - 比较C中的float和double