NULL represents an unknown or missing value. Equality comparisons with NULL do not evaluate to TRUE, which affects JOIN matching.
Incorrect NULL handling can cause missing records, unexpected results, and inaccurate reports.
Identify customers whose optional region assignment is missing.
SELECT
c.CustomerName,
r.RegionName
FROM Customers c
LEFT JOIN Regions r
ON c.RegionID = r.RegionID;
Used in data quality, customer master data, financial reporting, and database validation.
- NULL does not equal NULL using =.
- LEFT JOIN can preserve rows with missing relationships.
- IS NULL is used to test for NULL.
- COALESCE can provide display defaults.
- NULL behavior should be considered in JOIN design.
Does NULL = NULL return TRUE?
No. SQL uses three-valued logic, so NULL comparisons using equality evaluate to UNKNOWN.
How do you check for NULL?
Use IS NULL or IS NOT NULL rather than = NULL or <> NULL.