Top myths for NULL value in SQL Queries
The below are some of the key points about nulls, and how to compare them. Just to make sure that you should know about what is NULL value.
- Interpretation is not exactly missing value.
- There could be many reasons why no value is present, e.g., value inappropriate.
How to compare NULL to values
In the below example the where condition just checks for TRUE condition. If not matches you will get UNKNOWN.Example:
Table Name is: Sells
bar beer price
=======================
Joe's bar Bud NULL
SELECT bar
FROM Sells
WHERE price < 2.00 OR price >= 2.00;
------------ -------------
UNKNOWN
Conclusion
Joe's Bar is not produced, even though the WHERE condition is correctly given. The reason is the price value is NULL. So, we should not compare NULL to values.
Comments
Post a Comment