|
|
Eliminating Duplicate Values
The simple SELECT statement retrieves all rows which fulfill the selection conditions. The result may contain duplicate values.
For example:
SELECT category_id FROM formats;Returns:
By adding the keyword DISTINCT before the column list you can eliminate all duplicate rows from the result table.
The keyword DISTINCT may only be used once in a simple SELECT statement.
For example:
SELECT DISTINCT category_id FROM formats;Returns:
DISTINCT also eliminates duplicate rows containing NULL values, although technically NULL is not regarded as equal to NULL, see Handling NULL Values.
If the selected columns include the whole primary key in the source table, the keyword DISTINCT is unnecessary, since all rows in the result table will be unique. Remember however that a view may contain duplicate rows, so that selecting all columns does not always guarantee that the result does not contain duplicate rows.
|
Mimer Information Technology AB Voice: +46 18 780 92 00 Fax: +46 18 780 92 40 info@mimer.se |
|
|