"What departments do we even have?" "Which countries do we ship to?" Questions about the unique values in a column come up constantly — and DISTINCT answers them in one word.
SELECT DISTINCT collapses duplicate rows into one, leaving each distinct value exactly once.
See it
Five employees, but only three departments — the repeats fold away:
| department |
|---|
| Engineering |
| Sales |
| Engineering |
| Sales |
| Marketing |
DISTINCT department| department |
|---|
| Engineering |
| Sales |
| Marketing |
Try it now — write the query that produces that list, returning each department once.
Your turn · Exercise
Return the distinct list of departments (each department once).
The data
employees
5 rows returned
| name | department |
|---|---|
| Ada | Engineering |
| Bo | Sales |
| Cy | Engineering |
| Di | Sales |
| Eli | Marketing |
It applies to the whole row
One subtlety worth knowing early: DISTINCT de-duplicates the entire selected row, not one column. SELECT DISTINCT department, city returns unique combinations of department and city — which may be more rows than unique departments alone. Run it and count:
From practice
When a list looks "too long" or has obvious repeats, SELECT DISTINCT is the fastest sanity check there is. Later, in the aggregation lesson, you'll meet its counting cousin: COUNT(DISTINCT col).
SELECT DISTINCT department, city returns…
That's the full result-shaping toolkit: SELECT … FROM picks columns, WHERE picks rows, ORDER BY sorts, LIMIT cuts, DISTINCT de-duplicates. Next: filtering with more than one condition — ranges, lists, text patterns, and the tricky case of missing values.