v***v 发帖数: 267 | 1 with a1 (ID1,ID2) as ( VALUES ('A', ''), ('B', NULL), ('C', 'A')) select *
from a1 where ID1 not in (select ID2 from a1)
就是想找id1不出现在id2里面的行
事先不知道id2里面有NULL
结果就一行都没选上 | i*******d 发帖数: 81 | 2 google "not in null sql".
always tested in SQL exams and it is the #1 common SQL mistake.
https://www.simple-talk.com/sql/t-sql-programming/ten-common-sql-programming
-mistakes/
*
【在 v***v 的大作中提到】 : with a1 (ID1,ID2) as ( VALUES ('A', ''), ('B', NULL), ('C', 'A')) select * : from a1 where ID1 not in (select ID2 from a1) : 就是想找id1不出现在id2里面的行 : 事先不知道id2里面有NULL : 结果就一行都没选上
| c*********e 发帖数: 16335 | 3 with a1 (ID1,ID2) as ( VALUES ('A', ''), ('B', NULL), ('C', 'A')) select *
from a1 where ID1 not in (select ID2 from a1 where ID2 IS NOT NULL)
*
【在 v***v 的大作中提到】 : with a1 (ID1,ID2) as ( VALUES ('A', ''), ('B', NULL), ('C', 'A')) select * : from a1 where ID1 not in (select ID2 from a1) : 就是想找id1不出现在id2里面的行 : 事先不知道id2里面有NULL : 结果就一行都没选上
| v***v 发帖数: 267 | 4 原来如此
谢谢各位
同事问起
花了我一下午才搞明白原来她那列里面有NULL | s**********o 发帖数: 14359 | 5 TEST NULL只有 IS NULL 或者IS NOT NULL
其他的就当不存在 |
|