Beginner Case 9 of 50

Case 009: Orders Per Customer

customersorders

The manager is putting together ByteMart's first loyalty program, and wants to know who actually qualifies before deciding on the tiers.

"How many times has each person actually ordered? I need the full list — everyone, even the customers who've never bought a thing."

The data Alex is looking at

customers
idnamecountry
1SamGermany
2NinaCanada
3DavidBrazil
4MayaJapan
5DanielAustralia
… 1 more row
orders
idcustomer_idproductamountorder_date
1011Keyboard25002026-01-05
1023Mouse12002026-01-08
1032Headphones35002026-01-10
1044Monitor120002026-01-12
1051Webcam45002026-02-03
… 4 more rows
TASK

Help Alex answer the manager:

“Show how many orders each customer has placed (including customers with zero).”
SQL editor Ctrl+Enter to run
Write a query above and hit Run to see what comes back.
No hints requested yet — click "Get a hint" when you're stuck.
Alex's final query — this is for reference. Copy it into your own thinking, not into the editor above.
SELECT customers.name, COUNT(orders.id) AS order_count FROM customers LEFT JOIN orders ON customers.id = orders.customer_id GROUP BY customers.name;
What that query returns
Case Debrief GROUP BY, COUNT
  • GROUP BY collapses rows into groups; COUNT() tells you how many rows landed in each group.
  • COUNT(column) skips NULLs (empty/missing values) — exactly why it correctly shows 0 for unmatched LEFT JOIN rows, instead of 1.

Case closed.

Ready for the next one?

Next: Case 010 — The Big Spenders →