The DISTINCT clause acts as a filter to remove duplicate records from a result set. It ensures that any records that are returned are unique for the column or columns specified in the SELECT statement. A duplicate row is defined as a row with matching values for each expression in the SELECT list. The DISTINCT keyword is synonymous with the UNIQUE keyword, which is non-standard SQL. Do not use "UNIQUE".
Note that the DISTINCT clause can only be used with select statements; it cannot be used in INSERT, UPDATE, or DELETE statements. You also cannot specify DISTINCT if the SELECT list contains LOB columns.
SELECT DISTINCT column_name(s) ...
Multiple column names (and tables) may be specified in the SELECT statement. This example will select a list of unique last names in each state:
SELECT DISTINCT state, last_name
Related Code Snippets: