AnalystPracticeGuides
DashboardSign up

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.

Watch it solved. Q3: count unique values (COUNT DISTINCT), from 1:48, in our video “SQL Interview Questions and Answers for Data Analysts (Easy to Hard)”. Pressing play loads the video from YouTube (privacy). Open on YouTube

How does it work on one column?

SELECT DISTINCT country
FROM customers;

returns each country once.

What happens with two columns?

SELECT DISTINCT country, city
FROM 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.

Try it yourself. Practise this in a real database in your browser, with instant feedback.
Practise SELECT DISTINCT

Updated November 2026.

← All free guides