Entering content frame

DISTINCT Function (distinct_function) 

The DISTINCT function ( distinct_function) is a set function that removes duplicated values and all NULLvalues.

Syntax

<distinct function>::= <set function name> ( DISTINCT <expression> )

set_function_name, expression

Explanation

The argument of a DISTINCT function is a set of values that is calculated as follows:

...

       1.      A result table or group (the result table can be grouped with a GROUP condition) is formed.

       2.      The expression is applied to each row in this result table or group.
The expression must not contain a set function.

       3.      All of the NULL values and duplicated values are removed (DISTINCT). Special NULL values are not removed and two special NULL values are considered identical.

The DISTINCT function is executed taking into account the relevant set function name for this set of values.

 

 

Result of the DISTINCT function

Set of values is empty and the DISTINCT function is applied to the entire result table

The set functions AVG, MAX, MIN, STDDEV, SUM, VARIANCE supply the NULL value as their result.

The set function COUNT supplies the value 0.

There is no group to which the DISTINCT function can be applied.

The result is an empty table.

The set of values contains at least one special NULL value.

Special NULL value

Example table: customer

In how many cities do the customers live?

SELECT COUNT(DISTINCT city) number_cities FROM customer

number_cities

4

 

 

Leaving content frame