What is the result of following query?

SELECT
CASE WHEN null = null
THEN ‘True’
ELSE ‘False’
END AS Result;

Answer: In SQL null can not be compared with itself. There fore null = null is not true. We can compare null with a non-null value to check whether a value is not null.

Therefore the result of above query is False.

The correct way to check for null is to use IS NULL clause.

Following query will give result True.

SELECT
CASE WHEN null IS NULL
THEN ‘True’
ELSE ‘False’
END AS Result;

Leave a Reply

Your email address will not be published. Required fields are marked *