DISTINCT keyword is used to eliminate duplicate rows from a
result.
To eliminate duplicate rows :
Syntax of using DISTINCT keyword in select clause :
SELECT DISTINCT columns
FROM table
Example of without using DISTINCT keyword in select clause :
SELECT Country, City
FROM Suppliers
ORDER BY Country, City
Output
Country City
Australia Melbourne
Australia Melbourne
Brazil Sao Paulo
Canada Montréal
Canada Ste-Hyacinthe
Finland Lappeenranta
France Montceau
France Montceau
France Annecy
As you can see that above query returns multiple rows having duplicate
value. Country and city columns having value 'australia and melbourne'
and 'France and montceau' are displaying twice in a result. You can
eliminate duplicate value by below example.
Example of using DISTINCT keyword in select clause :
SELECT DISTINCT Country, City
FROM Suppliers
ORDER BY Country, City
Output
Country City
Australia Melbourne
Brazil Sao Paulo
Canada Montréal
Canada Ste-Hyacinthe
Finland Lappeenranta
France Montceau
France Annecy
Using distinct keyword, duplicate rows from result are
eliminated. Country and city columns having value 'australia and melbourne' and 'France and montceau' are displaying only once in a result.