Why does the following query return an empty set?
SELECT *
FROM null_test_tab
WHERE col1 = NULL
ORDER BY id
Result:
Empty set
Why does the following query return an empty set?
SELECT *
FROM null_test_tab
WHERE col1 = NULL
ORDER BY id
Result:
Empty set
The expression should be col is null
. The result of an arithmetic comparison with null
, such as col = null
, is null.
Take a look at: https://dev.mysql.com/doc/refman/8.0/en/working-with-null.html
Try this:
SELECT *
FROM null_test_tab
WHERE col1 IS NULL ORDER BY id
Here,NULL means “a missing unknown value”.
To test for NULL, use the IS NULL and IS NOT NULL operators.
You cannot use arithmetic comparison operators such as =, <, or <> to test for NULL.
For more details check the following from mySQL doc
https://dev.mysql.com/doc/refman/8.0/en/working-with-null.html