COUNT(*) vs COUNT(column) in SQL (And SUM vs COUNT)
COUNT(*) counts rows. COUNT(column) skips NULLs. SUM adds numbers. Know which aggregate answers which business question.
COUNT(*) — how many rows?
SELECT COUNT(*) AS total_customers FROM customers;
Includes every row, even if some columns are NULL. This is the usual answer to “how many customers / orders?”
COUNT(column) — skip NULLs
SELECT COUNT(status) AS rows_with_status FROM orders;
If status can be NULL, this number can be smaller than COUNT(*).
SELECT COUNT(*) AS all_orders, COUNT(status) AS orders_with_status FROM orders;
Run both on the same table when you suspect missing values — the gap is exactly how many NULLs you have in status.
SUM vs COUNT
COUNT(order_id)→ number of order rowsSUM(qty)→ total units sold (needs a numeric column)COUNT(DISTINCT city)→ how many unique cities
Mixing them up is how “average order size” reports go sideways.
FAQ
What is the difference between COUNT(*) and COUNT(column)?
COUNT(*) counts every row. COUNT(column) counts only rows where that column is not NULL.
When should I use SUM instead of COUNT?
Use COUNT for “how many rows/orders.” Use SUM for “how much quantity/revenue.”
Try it yourself
The fastest way to lock this in is a short drill on the same Northstar Market tables.