InterviewPrepKit

Home / SQL / Query Basics

Distinct Product Categories

easy 00:00
Solving tips
  • Use SELECT DISTINCT to collapse repeated values into a unique set.
  • DISTINCT applies to the whole selected row, so list only the column you want deduplicated.
  • Add ORDER BY when the task requires a stable, predictable ordering of the results.

You are given a product catalog where many products share a category. Produce the list of unique categories for a filter menu.

Schema

CREATE TABLE products (
  id       INTEGER PRIMARY KEY,
  name     TEXT,
  category TEXT,
  price    NUMERIC(10,2)
);

Sample data:

idnamecategoryprice
1LaptopElectronics1200.00
2MouseElectronics25.00
3DeskFurniture300.00
4ChairFurniture150.00
5NotebookStationery5.00
6MonitorElectronics400.00
7PenStationery2.00

Task

Return each distinct category exactly once, with the column aliased as category. Order the results alphabetically in ascending order.

Expected output

category
Electronics
Furniture
Stationery

Write your solution, then hit Run tests to check it — or get a mock grade from the AI coach.

The coach remembers this session — revise your code and ask again, and it grades your progress. It gives hints, not the answer.
Report a bug