Complete Category Buyers
Amazon ☯️ Medium SQL
Beginner Mode

Objective

Write a SQL query to identify the customer IDs of those who have purchased at least one product from every product category.

Table Schema:

  • customer_purchases
Column Type Description
purchase_id INTEGER Unique identifier for each purchase
customer_id INTEGER ID of the customer
product_id INTEGER ID of the purchased product
  • product_catalog
Column Type Description
product_id INTEGER Unique identifier for each product
product_name VARCHAR Name of the product
category VARCHAR Product category

Task Requirements:

  • Join purchase data with the product catalog to determine which categories each customer has bought from
  • Identify customers who have covered every distinct category in the catalog
  • A customer may have multiple purchases in the same category - this still counts as one category
  • Sort the result by customer_id in ascending order

Output columns: customer_id

Examples

Example 1:

Input:

customer_purchases
customer_idproduct_idpurchase_id
111
132
153
214
225
326
347
358
product_catalog
categoryproduct_idproduct_name
Electronics1Laptop
Electronics2Phone
Clothing3Shirt
Clothing4Pants
Kitchen5Blender

Output:
customer_id
1
3
Quick Solution

Code Environment

Sign in or try as guest to run your code.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →