SQL DISTINCT

SELECT DISTINCT removes duplicate rows from a result. Use it to list the unique values in a column, like every city your customers live in.

Updated December 1, 2026

Syntax

SELECT DISTINCT column1, column2
FROM table_name;

List unique values

The drinks table has 10 rows but only three categories.

SELECT DISTINCT category
FROM drinks;
Result on the SQL Café sample data (3 rows)
category
coffee
tea
other

DISTINCT and NULL

DISTINCT treats all NULL values as one value, so a missing city appears once in the list.

SELECT DISTINCT city
FROM customers;
Result on the SQL Café sample data (4 rows)
city
Austin
Seattle
Denver
NULL

Count unique values

COUNT(DISTINCT column) counts different non-null values. Fay has no city, so she isn’t counted.

SELECT COUNT(*) AS customers, COUNT(DISTINCT city) AS cities
FROM customers;
Result on the SQL Café sample data (1 row)
customerscities
83

Common mistakes

Practice DISTINCT interactively

Write real queries in your browser and get instant feedback in the lesson “Rename and dedupe” (Unit 1). New learners can start free from the first lesson.

Frequently asked questions

What is the difference between DISTINCT and GROUP BY?

For listing unique values they give the same rows. Use GROUP BY when you also want to count or total something for each value.

Is DISTINCT slow?

It has to compare rows to find duplicates, so it adds work on large results. That’s usually fine, but don’t add it “just in case”.

Related SQL tutorials