2015-10-10 72 views
1

我知道这是一个非常简单的问题,但为什么不是我的查询返回任何东西?多在哪里在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) 

回答

0

action = null更改为action is null

0

尝试IS NULL

select id 
from notifications 
where user_id = 1 
and action IS NULL 
1

NULL不能等于任何东西,包括自己。你应该使用它is ..

select id from notifications where user_id = 1 and action is NULL;