What is DISTINCT?
- SQL course
- Beginner
- Lesson 65/115
- 4 min
Remove duplicate rows with DISTINCT.
What is DISTINCT?
With DISTINCT you remove duplicate rows from a result. It goes right after SELECT.
SELECT DISTINCT city FROM customers;This query lists the unique cities in the customer table.
city is selected from customers (DISTINCT removes duplicates).
What is DISTINCT? — details
DISTINCT applies to all columns; it deduplicates whole rows, not a single column. Duplicate rows appear once.
Practice What is DISTINCT?
Select unique cities from customers.
Starter code
-- unique cities
SELECT
FROM customersSample solution
SELECT DISTINCT city
FROM customersExpected output
city İstanbul İzmir Bursa
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What does DISTINCT do?
- Sorts rows
- Adds rows
- Deletes rows
- Removes duplicate rows Correct answer
Explanation: DISTINCT removes duplicates.
2 Deduplicate
SELECT ____ city FROM customers;
SELECT DISTINCT city FROM customers;
Explanation: DISTINCT is the right answer.
3 What is DISTINCT: match the terms
| Term | Meaning |
|---|---|
DISTINCT |
deduplicate |
SELECT |
columns |
FROM |
table |
WHERE |
filter |