Mimer SQL Documentation TOC PREV NEXT INDEX

Mimer SQL Developer Site


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:

CATEGORY_ID
1
1
1
1
2
2
2
2
3
3

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:

CATEGORY_ID
1
2
3

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
Mimer Information Technology AB
Voice: +46 18 780 92 00
Fax: +46 18 780 92 40
info@mimer.se
Mimer SQL Documentation TOC PREV NEXT INDEX