Difficulty: Beginner
Estimated time: 5–10 minutes
SQL concepts: DISTINCT, unique values, de-duplication
Goal: Return unique values from a column (a common reporting requirement).
The Scenario
A product manager asks:
“Which product categories do we currently have?”
They don’t want a full product list. They want a unique list of categories—no duplicates.
Your task is to query the products table and return each category only once.
Database Table
products
| column_name | type | description |
|---|---|---|
| product_id | INTEGER | Unique product ID |
| name | TEXT | Product name |
| category | TEXT | Product category |
| price | DECIMAL | Product price |
| stock_qty | INTEGER | Units in stock |
| created_at | TIMESTAMP | When the product was created |
Sample Data (for context)
| product_id | name | category | price |
|---|---|---|---|
| 101 | Wireless Mouse | Accessories | 24.99 |
| 102 | Mechanical Keyboard | Accessories | 89.00 |
| 103 | 27-inch Monitor | Displays | 229.99 |
| 104 | USB-C Hub | Accessories | 34.50 |
| 105 | Laptop Stand | Workspace | 39.99 |
Your Task
Write a SQL query that returns a unique list of:
category
From the products table.
Expected Output
| category |
|---|
| Accessories |
| Displays |
| Workspace |
(Order is not required unless you add ORDER BY.)
Constraints
- Use
DISTINCT - Return only the
categorycolumn - Do not use
GROUP BY(we’ll cover that later)
Hint (Optional)
DISTINCT removes duplicate rows from your result set based on the selected columns.
SELECT DISTINCT
category
FROM products;
Explanation
DISTINCTensures duplicate category values are collapsed into a single result.- This is often used for:
- Dropdown lists
- Summary reporting
- Data validation checks
Common Mistakes
- Using
DISTINCTon the wrong columnsSELECT DISTINCT category, name FROM products;This returns unique pairs of category + name, not unique categories. - Assuming
DISTINCTsorts resultsDISTINCTdoes not sort. If you want sorting, addORDER BY.
Optional Extension (Mini Bonus)
- Return unique categories sorted alphabetically.
- Return unique categories only for Accessories-priced products above 50 (combine
WHERE+DISTINCT).
Next Challenge
If you want to keep going, the next beginner step is:
Beginner Challenge #6: Group and Summarize with GROUP BY
🔗 View reference solution on GitHub
(After you’ve tried the challenge)
Want more practical SQL challenges?
Subscribe to the Solve With SQL newsletter and get new problems delivered to your inbox.