runtime
62 / 88

task IN / EXISTS / NOT EXISTS · hard

Find shoppers in every category

Return shoppers who bought at least one item from every distinct category currently in catalog_items, considering only delivered orders.

what to return

Columns
shopper_idname in this order
Rows
1 row · in the order asked
Watch for
Derive the required category set from the catalog; do not hardcode four categories or named categories.
Multiple products and orders in one category count only once. Include every qualifying shopper and order by shopper_id.
This exercise adds two illustrative orders to the standard Harbor Market data; previews include them.
Skill
Find entities related to every member of a changing required set. Refresher: Multi-grain joins without fan-out →

expected result

Your query should return exactly these columns and values. Run it and compare.

expected result1 row · in this order
shopper_idname
1Ana Ruiz

all 1 rows

data you can query

Sample rows from each table. Each column shows its type underneath; → marks a link to another table.

shoppers5 columns · 17 rows
idinteger · keynametextemailtextregiontextsignup_datetext
1Ana Ruizana@harbor.testWest2025-01-03
2Ben Okaforben@harbor.testEast2025-01-05
3Chloe Parkchloe@harbor.testWest2025-01-09
4Dmitri Volkovdmitri@harbor.testNorth2025-01-14
5Esi MensahNULLSouth2025-01-20

showing 5 of 17 rows

catalog_items4 columns · 13 rows
idinteger · keynametextcategorytextpricereal
1Desk LampLighting39
2Floor lampLighting89
3String LightsLighting19.5
4Chef KnifeKitchen59
5Cast Iron PanKitchen45

showing 5 of 13 rows

sales_orders5 columns · 33 rows
idinteger · keyshopper_idinteger → shoppersorder_datetextstatustextdelivered_datetext
10112025-01-04delivered2025-01-08
10222025-01-06delivered2025-01-07
10312025-01-15delivered2025-01-20
10432025-01-18cancelledNULL
10542025-01-22delivered2025-01-31

showing 5 of 33 rows

order_lines4 columns · 48 rows
order_idinteger → sales_ordersitem_idinteger → catalog_itemsquantityintegerunit_pricereal
1011139
1013219.5
1024159
1035145
10310312

showing 5 of 48 rows

solution.sql
 

Hints and the answer are always available. Using them counts the question as solved with help.