SELECT DISTINCT removes duplicate rows from the result.
Without DISTINCT, a city appears once per customer. With it, each city appears only once.
Count unique values with COUNT(DISTINCT column).
Return only unique values.
✍️ 3 exercises + code challenge in this lessonSELECT DISTINCT removes duplicate rows from the result.
Without DISTINCT, a city appears once per customer. With it, each city appears only once.
Count unique values with COUNT(DISTINCT column).
Mastering SQL SELECT DISTINCT helps you write clean and reliable SQL code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
SELECT DISTINCT Country FROM Customers;
SELECT COUNT(DISTINCT City) AS UniqueCities FROM Customers;
Check what you learned in “SQL SELECT DISTINCT”.
Return each country only once.
SELECT Country FROM Customers;
What does DISTINCT remove?
Select the distinct categories from Products, sorted alphabetically.
Free sign-in required · Google login available
Stuck on something?
Ask the community in the CodesInTech forum.
Need a developer?
Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.
Explore Our Services