0

In mysql table real_account_id's data type is int(11). I want to fetch all records with NULL values.

I am using this simple query.

SELECT * FROM `customer_payment_options` WHERE real_account_id = NULL

But, it's not giving me any results. There are 2 records in database with NULL value. I also tried with,

SELECT * FROM `customer_payment_options` WHERE real_account_id = 'NULL'

Why is it like this? Thanks.

John Conde
  • 212,985
  • 98
  • 444
  • 485
Ronak Patel
  • 5,341
  • 9
  • 54
  • 129

1 Answers1

7

NULL is equal to nothing including NULL. That's why you must use IS NULL:

SELECT * FROM `customer_payment_options` WHERE real_account_id IS NULL
John Conde
  • 212,985
  • 98
  • 444
  • 485
  • Thanks. Is there any technical reason behind that? Because, comparing with `NULL` is the same thing – Ronak Patel Jul 11 '14 at 19:21
  • 1
    To tell you the truth I am not sure why this is. A maybe good explanation can be found [here](http://stackoverflow.com/a/16463613/250259). – John Conde Jul 11 '14 at 19:28