SQL Select Distinct

The SQL SELECT Distinct Statement

The SELECT DISTINCT statement is used to return only distinct (different) values.

Inside a table, a column often contains many duplicate values; and sometimes you only want to list the different (distinct) values.

SELECT DISTINCT Syntax

SQL
SELECT DISTINCT column1, column2, ...
FROM table_name; 

SELECT Example Without DISTINCT

The following SQL statement selects all (including the duplicates) values from the “Country” column in the “Customers” table:

SQL
SELECT Country FROM Customers;

SELECT DISTINCT Examples

The following SQL statement selects only the DISTINCT values from the “Country” column in the “Customers” table:

SQL
SELECT DISTINCT Country FROM Customers;

The following SQL statement lists the number of different (distinct) customer countries:

SQL
SELECT COUNT(DISTINCT Country) FROM Customers;