问题存在于MySQL的最新版本中,所以我甚至怀疑这可能是一个错误.
这是两个表:
t1(id int), values (10),(2)
t2(id int), values (0),(null),(1)
执行:
select id from t1 where id > all (select id from t2);
返回结果集:
+------+
| id   |
+------+
|   10 |
|    2 |
+------+
根据我的知识和页面http://dev.mysql.com/doc/refman/5.5/en/all-subqueries.html
该语句应返回空结果!因为"where"中的每个判断都会导致null,如下所示:
select id > all (select id from t2)  as c1 from t1;
收益:
+------+
| c1   |
+------+
| NULL |
| NULL |
+------+
实际上select id from t1 where null;什么也没有回报
最后,我尝试了这个:
explain extended select id from t1 where …我用的时候
Select Distinct Brand_ID
from db.ABC
WHERE
Brand_ID <> 800
我得到了返回的输出:
+----------+
| Brand_ID |
+----------+
|      100 |
|      200 |
|      300 |
|      400 |
|      500 |
|      600 |
|      700 |
|      900 |
+----------+
但是,该列确实包含NULL值,它们存在.我需要更新我的select语句以明确说:
Select Distinct Brand_ID
from db.ABC
WHERE
Brand_ID <> 800 OR Brand_ID IS NULL
要获得正确的输出:
+----------+
| Brand_ID |
+----------+
| NULL     |
| 100      |
| 200      |
| 300      |
| 400      |
| 500      |
| …