|
|
Eliminating Duplicate Values
The simple
SELECTstatement 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
DISTINCTbefore the column list you can eliminate all duplicate rows from the result table.The keyword
DISTINCTmay only be used once in a simpleSELECTstatement.For example:
SELECT DISTINCT category_id FROM formats;Returns:
DISTINCTalso eliminates duplicate rows containingNULLvalues, although technicallyNULLis not regarded as equal toNULL, see Handling NULL Values.If the selected columns include the whole primary key in the source table, the keyword
DISTINCTis 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 |
|
|