1
中我确实有两个表表1和表2。而且其内容如下当空值存在时,Mysql不返回任何值在子查询
mysql> select id from table1;
+------+
| id |
+------+
| 1 |
| 2 |
| 3 |
| 4 |
+------+
4 rows in set (0.00 sec)
mysql> select id from table2;
+------+
| id |
+------+
| 301 |
| 2 |
| NULL |
+------+
3 rows in set (0.00 sec)
时,我打下面的查询在MySQL控制台,它总是返回空集
select id
from table1
where id
not in (select id from table2);
空集(0.00秒)
是否有一个原因,当在子查询中有空值在和不在会发生故障....?
我已经通过使用下面的查询
select id
from table1
where id
not in (select id from table2 where id is not null);
+------+
| id |
+------+
| 1 |
| 3 |
| 4 |
+------+
3行中集(0.00秒)
解决它只是想提前知道
谢谢:)
编辑:This question试图清除一些空气但不够
可能重复[为什么MYSQL IN关键字不考虑NULL值](http://stackoverflow.com/questions/10810391/why-mysql-in-keyword-not-considering-null-values) –
欢迎来到世界*三值逻辑*:https://en.wikipedia.org/wiki/Three-valued_logic#Application_in_SQL – dnoeth