Skip to main content
Admissions guidance, study banks, and career tools — get started on Shalyam

Customers Who Bought All Products

Medium Subqueries

Return the customer_id of every customer who has bought every product listed in the Products table.

Table schema

Products(id INT PRIMARY KEY)
Purchases(customer_id INT, product_id INT)

Sample data

Products: 1, 2, 3

Purchases:
customer_id | product_id
1 | 1
1 | 2
1 | 3
1 | 1
2 | 1
2 | 2
3 | 3

Discussion

No discussions yet.

Rewards · v2.1

Get Exclusive Insights with Every Issue

Join Shalyam Newsletter

Stay ahead in education, research, and innovation—straight to your inbox.