SQL SELECT DISTINCT

Return only unique values.

✍️ 3 exercises + code challenge in this lesson

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).

Key Takeaways: SQL SELECT DISTINCT

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.

SQL SELECT DISTINCT Code Example

SQL
SELECT DISTINCT Country FROM Customers;

SELECT COUNT(DISTINCT City) AS UniqueCities FROM Customers;
Free sign-in required · Google login available

SQL SELECT DISTINCT Practice Exercises

Check what you learned in “SQL SELECT DISTINCT”.

/ 3 solved
Fill in the blank

Return each country only once.

SELECT  Country FROM Customers;
✓ Correct! Not quite. Try again.
Multiple choice

What does DISTINCT remove?

✓ Correct! Not quite. Try again.
Code challenge

Select the distinct categories from Products, sorted alphabetically.

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

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