【发布时间】:2016-10-12 08:41:20
【问题描述】:
我确实有两个表 table1 和 table2。其内容如下
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 秒)
当子查询中有空值时 in 和 not in 是否会出现故障......?
我已经通过使用以下查询解决了它
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 试图清除一些空气,但还不够
【问题讨论】: