Home / SQL / Reference / Querying

SQL DISTINCT

Remove duplicate rows from the result.

Syntax

SELECT DISTINCT column1, column2 FROM table;

With several columns, a row is a duplicate only if all the listed columns are equal. COUNT(DISTINCT col) counts different values.

Example

Query (on the shop database used in the SQL course)

SELECT DISTINCT country
FROM customers
ORDER BY country;

Result

country
Australia
Nepal
New Zealand
United Kingdom

4 rows

Related

Learn it step by step in the free lesson SELECT: Choosing Columns, with exercises that check your queries.