Intermediate Case 27 of 50

Case 027: Bought Both

customersordersorder_itemsproducts

The Audio and Accessories teams want to run a joint bundle promo.

The manager relays their ask: "I need customers who've bought from BOTH categories — not one or the other. Could you pull that list?"

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 bought from BOTH the 'Audio' category and 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 customers.id IN ( SELECT orders.customer_id FROM orders JOIN order_items ON order_items.order_id = orders.id JOIN products ON products.id = order_items.product_id WHERE products.category = 'Audio' INTERSECT SELECT orders.customer_id FROM orders JOIN order_items ON order_items.order_id = orders.id JOIN products ON products.id = order_items.product_id WHERE products.category = 'Accessories' );
What that query returns
Case Debrief INTERSECT (set operations)
  • INTERSECT keeps only the rows that appear in both queries' results — exactly what you need when a customer must satisfy two separate conditions, not just one or the other.

Case closed.

Ready for the next one?

Next: Case 028 — The High-Value Customers →