DISTINCT gives one of each value
DISTINCT removes duplicate values, returning each different value only once. Without it, asking for the city column returns one row per café, so the same city repeats. With DISTINCT, the repeats fold together into a clean list of the values that exist.
A tiny example
In plain English: Show me the café cities, each city once.
SELECT DISTINCT city
FROM cafes;Query result
| city |
|---|
| Lisbon |
| Oslo |
| Porto |
Many cafés share a city, but each city appears only once here.
Common questions
- Does DISTINCT work on more than one column?
- Yes. SELECT DISTINCT city, drink returns each different city-and-drink pair once. The same city can appear again as long as it is paired with a different drink.
- Is DISTINCT the same as GROUP BY?
- For a plain list of unique values they return the same rows. GROUP BY is the one to reach for when you also want per-group numbers like COUNT(*) or SUM next to each value.
Related SQL lessons
Ready for a break?
A fresh, bite-sized SQL puzzle waits every morning. Tap tiles, see real results. No terminal, no setup, no timers.
Try today's free SQL puzzle