Ravindra BagaleCourses & study guides Track your progress

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

  1. Run both counts.
  2. Explain the gap as missing notes.
  3. 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_ordersorders_with_note
242

Meaning. Gap = rows where note is NULL.

Ravindra Bagale's Tip

AVG also ignores NULLs — useful, but know what you are averaging.