Explore Library
Code Quiz

LEFT JOIN Count Miscounts Zero Orders

A LEFT JOIN with COUNT(*) wrongly reports 1 for customers who have no orders.

Codesql
SELECT c.customer_id,
       c.name,
       COUNT(*) AS order_count
FROM customers c
LEFT JOIN orders o
       ON o.customer_id = c.customer_id
GROUP BY c.customer_id, c.name
ORDER BY order_count DESC;

What is the bug in this query that lists each customer's order count?