多个在mysql查询中没有返回任何内容的地方

时间:2015-10-10 04:19:29

标签: mysql

我知道这是一个非常简单的问题,但为什么我的查询不返回任何内容?

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)

3 个答案:

答案 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