CodeBlanks Logo Icon CodeBlanks

What is DISTINCT?

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

query.sql
-- unique cities
SELECT
FROM customers

Sample solution

query.sql
SELECT DISTINCT city
FROM customers

Expected 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

Question
SELECT ____ city FROM customers;
Answer
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

All lessons in Beginner