SQL SELECT DISTINCT
SELECT DISTINCT removes duplicate rows from the result. It applies to the whole row you select, not to one column, so with several columns you get unique combinations.
How does it work on one column?
SELECT DISTINCT countryFROM customers;
returns each country once.
What happens with two columns?
SELECT DISTINCT country, cityFROM customers;
returns each country and city combination once. Vienna appears once for Austria, but Austria appears once for every city.
How do you count unique values?
SELECT COUNT(DISTINCT customer_id)FROM orders;
counts customers who ordered, not orders. COUNT(*) would count every order.
DISTINCT or GROUP BY?
For a plain list of unique values they give the same result. As soon as you need a number per value, such as orders per country, use GROUP BY with an aggregate.
Common mistake
Adding DISTINCT to hide duplicates that come from a bad join. The duplicates are a symptom. Fix the join instead.
Practise SELECT DISTINCT
Updated November 2026.