How to use DISTINCT
Return unique values
Place DISTINCT after SELECT to collapse duplicate result rows.
SELECT DISTINCT city
FROM students;
Consider all selected columns
With several columns, uniqueness applies to the complete combination, not to each column independently.
SELECT DISTINCT city, country
FROM students;
Expect one NULL
When duplicate results are removed, multiple NULL values are represented by one NULL result.
Use it intentionally
DISTINCT can require sorting or hashing. If an unexpected join creates duplicates, fix the join rather than hiding the problem with DISTINCT.