InterviewPrepKit

Home / SQL / Query Basics

Distinct Product Categories

easy
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
Your workspace Not runnable by design — this is your interview scratchpad. Saved on this device.