Summary - DISTINCT
- SQL course
- Beginner
- Lesson 70/115
- 5 min
Write a report query with DISTINCT and COUNT(DISTINCT).
Summary - DISTINCT
In this group you learned DISTINCT alone, with multiple columns, with COUNT and inside aggregates. Cleaning duplicates is now easy.
SELECT COUNT(DISTINCT city) AS n FROM customers;This query counts how many distinct cities there are.
COUNT(DISTINCT city) AS n is selected from customers.
Practice Summary - DISTINCT
Select unique categories from products.
Starter code
-- summary distinct
SELECT
FROM productsSample solution
SELECT DISTINCT category
FROM productsExpected output
category kitap kırtasiye aksesuar
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which removes duplicates?
- DISTINCT Correct answer
- COUNT
- SUM
- WHERE
Explanation: DISTINCT removes duplicate rows.
2 Summary - DISTINCT: match the terms
| Term | Meaning |
|---|---|
DISTINCT |
deduplicate |
COUNT |
count |
SUM |
sum |
AVG |
average |