SQL Practice Problem #011

List unique product categories

Return each product category only once from the products table.

Problem

Task

Return each product category only once from the products table.

Schema

Table Schema

products(id, title, category, price, rating)

Input

Sample Data

idtitlecategorypricerating
1KeyboardAccessories49.994.6
2MouseAccessories24.54.3
3MonitorDisplays2194.8

Output

Expected Output

category
Accessories
Displays

Answer

Check Your Solution

Show Answer and Explanation

Correct Answer

SELECT DISTINCT category
FROM products
ORDER BY category;

Explanation

DISTINCT removes duplicate category values from the result. ORDER BY category makes the output order predictable.

Common Mistakes

  • Using GROUP BY only to remove duplicates when DISTINCT is clearer.
  • Selecting extra columns such as title, which makes the rows unique again.
  • Forgetting ORDER BY when the result order needs to be predictable.

Concepts

Related Concepts

DISTINCT Projection Result Sets SELECT

Next practice

Related Problems