TheAnalyst / SQLAll lessons ↗
Day 8 · Aggregation & joins · 10–20 minutes

DISTINCT and deduplication

DISTINCT returns unique combinations of selected columns.

01 · Learn

The idea

DISTINCT returns unique combinations of selected columns. Read the query line by line and identify the input table, the transformation, and the shape of the result before running it.

SELECT DISTINCT country FROM customers ORDER BY country;
Read it actively

Before running the example, predict the output columns and whether the query returns one row, many rows, or possibly no rows.

02 · Recall

Explain it without looking

In your own words, explain the main SQL feature in today’s lesson and why it answers the question.

03 · Solve

Run your own query

List each country represented in customers exactly once.

Loading browser SQL engine…
04 · Repeat

Close the loop