Home / SQL Tutorial / Day 4
Day 4 — Empty values and NULL
NULL is the quiet cause of wrong numbers in reports. Half an hour today saves you a very bad afternoon later.
NULL means "we do not know"
NULL is not zero. It is not an empty string. It means no value was recorded. In our Customers table, Bose Logistics has no Segment.
This never works
Comparing anything to an unknown gives an unknown, not "true". You must use
WHERE Segment = NULL
Comparing anything to an unknown gives an unknown, not "true". You must use
IS NULL.IS NULL
IS NOT NULL
Why this quietly breaks reports
Run these two and add up the row counts.
Two plus five is seven — but there are eight customers. The row with a NULL Segment appears in neither result, because it is neither equal nor not-equal to 'Retail'. It is unknown.
The habit that saves you
Whenever a total does not tie out, check for NULLs first. Nine times out of ten in MIS work, that is the cause.
Managers and NULL
The Employees table uses NULL to mean "reports to nobody" — the top of the tree.
Try these yourself
- List customers with no Segment recorded.
- Count how many customers DO have a Segment.
- Find the employee with no manager.
- Show all customers, then explain why "= Retail" plus "<> Retail" does not add up to the total.
Want this taught properly?
This tutorial covers the basics. Our SQL course in Noida takes you through window functions, CTEs and stored procedures on a real database, with projects and mentor support.
See the SQL course →