Count orders per customer

Return customer name and their order count for every customer, ordered by customer id.

Try it yourself

Open a fresh temporary sample shop dataset. Write your query and use Check answer. Checking uses a separate, clean sample so edits to your workspace cannot change the expected answer. Matches are based on this dataset, not a proof for every possible database.

Open exercise →

Sample schema

customers(id, name, email, country, joined_at)
products(id, name, category, price)
orders(id, customer_id, ordered_at, status, total)
order_items(id, order_id, product_id, quantity, unit_price)

About this dataset · Learning paths · SQL reference

Show a hint

Use LEFT JOIN and COUNT(o.id), including customers without matches.

Show one solution
SELECT c.name, COUNT(o.id) FROM customers c LEFT JOIN orders o ON o.customer_id=c.id GROUP BY c.id ORDER BY c.id;

Other queries can produce the same answer. Column aliases are ignored; column order and row order are checked.

Keep practicing

Find missing contact details → · All exercises