13/30
Part 3 of 5 · NULLs and joinsLearn and do

COUNT(*) counts the NULL row, and IS NULL on a right-hand key keeps only the rows with no match

Dee's 0 comes from COUNT(o.order_id), which skips her NULL row. Swap in COUNT(*) and it counts that row:

SELECT c.name, COUNT(*) AS march_orders
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.customer_id
                  AND o.placed_at >= '2026-03-01'
                  AND o.placed_at < '2026-04-01'
GROUP BY c.customer_id, c.name
ORDER BY c.customer_id;
namemarch_orders
Ana2
Ben1
Cy1
Dee1

One right-hand condition belongs in WHERE on purpose. IS NULL on a right-hand key keeps only the rows that found no match. That's how you ask for customers with no March orders:

SELECT c.name
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.customer_id
                  AND o.placed_at >= '2026-03-01'
                  AND o.placed_at < '2026-04-01'
WHERE o.order_id IS NULL;
name
Dee

In the editor, fix APRIL_ORDERS: all three cities, with 0 where there were no April orders.