7. NULL Values: Missing Data Done Right
7.5 COUNT(*) vs COUNT(column) When NULLs Exist
Why. COUNT lies if you pick the wrong form when NULLs exist.
What. COUNT(*) counts rows. COUNT(column) skips NULLs in that column.
How. Compare COUNT(*) and COUNT(note) on orders.
Steps
- Run both counts.
- Explain the gap as missing notes.
- Same check on tickets.amount_eur.
Examples
Example 1 · dataset: raja_coffee
SELECT COUNT(*) AS all_orders,
COUNT(note) AS orders_with_note
FROM orders;Output
| all_orders | orders_with_note |
|---|---|
| 24 | 2 |
Meaning. Gap = rows where note is NULL.
Ravindra Bagale's Tip
AVG also ignores NULLs — useful, but know what you are averaging.
Ravindra Bagale's Tip – मराठी
AVG सुद्धा NULL वगळतो — उपयुक्त, पण कशाचा average हे जाणा.
Ravindra Bagale's Tip – हिंदी
AVG भी NULL छोड़ता है — उपयोगी, पर किसका औसत जानें।