SELECT DISTINCT returns only unique values (without duplicates).
DISTINCT operates on a single column.
List all French customer cities (without duplicates).
SELECT DISTINCT City
FROM Customer
WHERE Country = 'France'
City |
---|
Lille |
Lyon |
Marseille |
Nantes |
Paris |
Reims |
Strasbourg |
Toulouse |
Versailles |
DISTINCT syntax.
SELECT DISTINCT column-name FROM table-name
DISTINCT syntax with COUNT or other aggregates.
SELECT COUNT (DISTINCT column-name) FROM table-name
SUPPLIER |
---|
Id |
CompanyName |
ContactName |
City |
Country |
Phone |
Fax |
SELECT DISTINCT Country
FROM Supplier
ORDER BY COUNTRY
Country |
---|
Australia |
Brazil |
Canada |
Denmark |
SUPPLIER |
---|
Id |
CompanyName |
ContactName |
City |
Country |
Phone |
Fax |
SELECT COUNT (DISTINCT Country) AS Number
FROM Supplier
Number |
---|
16 |