SQL Beginner Challenge 5: Remove Duplicates with DISTINCT

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_nametypedescription
product_idINTEGERUnique product ID
nameTEXTProduct name
categoryTEXTProduct category
priceDECIMALProduct price
stock_qtyINTEGERUnits in stock
created_atTIMESTAMPWhen the product was created

Sample Data (for context)

product_idnamecategoryprice
101Wireless MouseAccessories24.99
102Mechanical KeyboardAccessories89.00
10327-inch MonitorDisplays229.99
104USB-C HubAccessories34.50
105Laptop StandWorkspace39.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 category column
  • 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

  • DISTINCT ensures duplicate category values are collapsed into a single result.
  • This is often used for:
    • Dropdown lists
    • Summary reporting
    • Data validation checks

Common Mistakes

  1. Using DISTINCT on the wrong columns
    SELECT DISTINCT category, name FROM products; This returns unique pairs of category + name, not unique categories.
  2. Assuming DISTINCT sorts results
    • DISTINCT does not sort. If you want sorting, add ORDER BY.

Optional Extension (Mini Bonus)

  1. Return unique categories sorted alphabetically.
  2. 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.