我知道这是一个非常简单的问题,但为什么我的查询不返回任何内容?
mysql> select * from notifications;
+----+---------+-------------+---------+--------+---------------------+
| id | user_id | sec_user_id | item_id | action | date |
+----+---------+-------------+---------+--------+---------------------+
| 1 | 1 | NULL | NULL | NULL | 2015-10-09 23:47:36 |
+----+---------+-------------+---------+--------+---------------------+
1 row in set (0.00 sec)
mysql> select id from notifications where user_id = 1 and action = NULL;
Empty set (0.00 sec)
答案 0 :(得分:1)
NULL
不能等于任何东西,包括它自己。您应该使用is
..
select id from notifications where user_id = 1 and action is NULL;
答案 1 :(得分:0)
将action = null
更改为action is null
。
答案 2 :(得分:0)
尝试使用IS NULL
:
select id
from notifications
where user_id = 1
and action IS NULL