Beginner Case 20 of 50

Case 020: Never Bought Accessories

customersordersorder_itemsproducts

The Accessories team wants the opposite list — the customers who've never once bought from them. The manager relays their request.

"Who has NEVER bought anything from Accessories? Those are the customers I need to target."

The data Alex is looking at

customers
idnamecountrysignup_date
1SamGermany2026-01-02
2NinaCanada2026-01-05
3DavidGermany2026-01-10
4MayaJapan2026-01-15
5DanielCanada2026-01-20
… 5 more rows
orders
idcustomer_idorder_date
10112026-01-05
10222026-01-08
10332026-01-12
10412026-01-20
10542026-02-01
… 23 more rows
order_items
order_idproduct_idquantity
10112
10121
10231
10323
10451
… 29 more rows
products
idnamecategoryprice
1KeyboardAccessories2500
2MouseAccessories1200
3HeadphonesAudio3500
4MonitorDisplays12000
5LaptopComputers60000
… 5 more rows
TASK

Help Alex answer the manager:

“Find every customer who has never bought a product from the 'Accessories' category.”
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 FROM customers WHERE NOT EXISTS ( SELECT 1 FROM orders JOIN order_items ON order_items.order_id = orders.id JOIN products ON products.id = order_items.product_id WHERE orders.customer_id = customers.id AND products.category = 'Accessories' );
What that query returns
Case Debrief NOT EXISTS
  • NOT EXISTS keeps a customer only if the subquery finds absolutely nothing for them — no Accessories order at all.
  • Maya and Laura, for example, never once bought anything from Accessories — the subquery comes back empty for both of them, so NOT EXISTS lets them through.

Case closed.

One quick stop before the next tier.

Next: Beginner Recap →