CodeBlanks Logo Icon CodeBlanks

Summary - DISTINCT

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

query.sql
-- summary distinct
SELECT
FROM products

Sample solution

query.sql
SELECT DISTINCT category
FROM products

Expected 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

All lessons in Beginner