CODE WORKSPACE

Customers who never ordered

Return c.customer_id, c.country, and c.created_at for customers who have no rows in orders. Order by customer_id.

LEFT JOIN orders, then WHERE o.order_id IS NULL keeps customers with no match.

Sample input

customersAll 6 customers.
customer_idcountrycreated_at
1US2025-11-02
2null2025-12-10
3GB2026-01-05
4IN2026-01-09
5US2025-10-01
6GB2026-01-15
ordersbuyer_id values that appear. Note customer 5 never appears as a buyer.
order_idbuyer_id
10011
10023
10034
10052
10066

Expected output

Expected outputOnly customer 5 has no orders, so the LEFT JOIN leaves order_id NULL and the anti-join keeps that row.
customer_idcountrycreated_at
5US2025-10-01

Constraints

LEFT JOIN customers to orders on orders.buyer_id = customers.customer_id, then keep only rows where orders.order_id IS NULL (the anti-join).

Expected skills

LEFT JOIN to preserve all customers and the anti-join pattern (IS NULL on the right key) to keep only unmatched rows.

SQL
Loading...

AI evaluation

Run the SQL query to inspect preview rows.