BeginnerCoder

Lesson 7 — DISTINCT

DISTINCT: remove duplicate rows

SELECT DISTINCT returns each different value only once. With several columns, a row counts as a duplicate only if all listed columns match. COUNT(DISTINCT column) counts how many different values there are.

SELECT DISTINCT genre FROM movies
SELECT COUNT(DISTINCT genre) FROM movies

Why it matters: "which countries do our customers come from?" is a DISTINCT question — and it is far cheaper than fetching every row.

Want it another way?
Task

Make both queries use DISTINCT. Expected: 3 cities (sorted), and the count 3.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.