SQL SELECT DISTINCT Statement

  • SELECT DISTINCT returns only distinct (different) values.
  • SELECT DISTINCT eliminates duplicate records from the results.
  • DISTINCT can be used with aggregates: COUNT, AVG, MAX, etc.
  • DISTINCT operates on a single column. DISTINCT for multiple columns is not supported.
The definitive guide
for data professionals


Order today!
 See 2 min video



The SQL SELECT DISTINCT syntax


The general syntax is:
SELECT DISTINCT column-name
  FROM table-name

Can be used with COUNT and other aggregates
SELECT COUNT (DISTINCT column-name)
  FROM table-name





SQL SELECT Examples




Problem: List all supplier countries in alphabetical order.
SELECT DISTINCT Country
  FROM Supplier
ORDER BY COUNTRY


Results: 16 rows

Country
Australia
Brazil
Canada
Denmark





Problem: List the number of supplier countries
SELECT COUNT (DISTINCT Country)
  FROM Supplier


Results:

Count
16