SQL interview question: customers who bought every category

MediumRelational division

Problem

Shared data rules

Find buyers who bought from every catalog category in September 2026, and count their September orders.

Example

Input: products
product_idcategoryRow note
11Produce
12Dairy
13Dairy← same category as 12
Input: orders
order_iduser_idcreated_atstatus
10112026-09-03 10:00delivered
10212026-09-10 12:00delivered
10322026-09-12 13:00delivered
Input: order_items
order_idcategoryRow note
101Produce
102Dairy
102Dairy← second item, same category
103Produce
103Produce← second item, same category
Output
user_iddelivered_orders
12

The catalog has two categories. Buyer 1 covered both over two orders; buyer 2 bought only produce.

Notes

Solve it free

Your query runs on PostgreSQL in your browser. No sign-up needed.

Skills it tests

More interview questions

All questions