SQL: DISTINCT Clause
The SQL DISTINCT Clause allows you to remove duplicates from the result set. The SQL DISTINCT Clause can only be used with SQL SELECT statements.
SQL DISTINCT Clause Syntax
The syntax for the SQL DISTINCT Clause is:
SELECT DISTINCT expressions FROM tables WHERE predicates;
SQL DISTINCT Clause Examples - Single field example
Let's look at the simplest SQL DISTINCT clause example. We can use the SQL DISTINCT Clause to return a single field that removes the duplicates from the result set.
SELECT DISTINCT city FROM suppliers;
This SQL DISTINCT example would return all unique city values from the suppliers table.
SQL DISTINCT Clause Examples - Multiple fields example
Let's look at how you might use the SQL DISTINCT Clause to remove duplicates from more than one field in your SQL SELECT statement.
SELECT DISTINCT city, state FROM suppliers;
This SQL DISTINCT Clause example would return each unique city and state combination. In this case, the DISTINCT applies to each field listed after the DISTINCT keyword.