Unique Values with DISTINCT
Remove duplicates.
Helen asks, which genres do we sell? If you select the genre column, you get thirty rows, with Mystery, Thriller, and the rest repeated over and over. She wants each genre just once.

- Which genres do we sell?
- Thirty rows, lots of repeats
- Each one just once
DISTINCT
Put distinct right after select. It removes repeated rows, so each value appears only once. We also sort the result, so it's easy to read. Run it. Nine genres, each listed once.
SELECT DISTINCT genre
FROM books
ORDER BY genre;โโโโโโโโโโโโโโ โ genre โ โโโโโโโโโโโโโโค โ Business โ โ Cooking โ โ Fantasy โ โ History โ โ Mystery โ โ Romance โ โ Self-help โ โ Technology โ โ Thriller โ โโโโโโโโโโโโโโ
Exploring a column
Distinct is great for exploring a column you don't know yet. What values can an order's status have? Run it. Four values. Delivered, shipped, returned, and cancelled. Now you know exactly what to type in a where test.
SELECT DISTINCT status
FROM orders;โโโโโโโโโโโโโ โ status โ โโโโโโโโโโโโโค โ delivered โ โ shipped โ โ returned โ โ cancelled โ โโโโโโโโโโโโโ
Summary
Distinct shows each value once. It's one of the first things to try on a new table. Next, the classic top N question, and how to get the next page of results.
Key takeaways- DISTINCT removes repeats
- Great for exploring
- Sort it to read it easily