Ciprian
Ciprian

Reputation: 3226

Multiple where in mysql query not returning anything

I know that this is a very easy question, but why isn't my query returning anything ?

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)

Upvotes: 1

Views: 38

Answers (3)

Hotdin Gurning
Hotdin Gurning

Reputation: 1819

try with IS NULL:

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

Upvotes: 0

Timothy Stepanski
Timothy Stepanski

Reputation: 1196

Change action = null to action is null.

Upvotes: 0

vidit
vidit

Reputation: 6461

NULL cannot be equal to anything, including itself. You should use is with it..

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

Upvotes: 1

Related Questions