1

Why does the following query return an empty set?

SELECT * 
   FROM null_test_tab 
   WHERE col1 = NULL
   ORDER BY id

Result:

Empty set
1

2 Answers 2

5

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

Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.