DB2 Version 9.7 for Linux, UNIX, and Windows

GREATEST scalar function

Read syntax diagramSkip visual syntax diagram
                            .---------------.      
                            V               |      
>>-GREATEST--(--expression----,--expression-+--)---------------><

The schema is SYSIBM.

The GREATEST function returns the maximum value in a set of values.

The arguments must be compatible and each argument must be an expression that returns a value of any data type other than ARRAY, LOB, XML, a distinct type based on any of these types, or a structured type (SQLSTATE 42815). This function cannot be used as a source function when creating a user-defined function. Because this function accepts any compatible data types as arguments, it is not necessary to create additional signatures to support user-defined distinct types.

The selected argument is converted, if necessary, to the attributes of the result. The attributes of the result are determined by all the operands based on the rules for result data types.

The result of the function is the largest argument value. If at least one argument can be null, the result can be null; if either argument is null, the result is the null value.

The GREATEST scalar function is a synonym for the MAX scalar function.

Examples:

Assume that table T1 contains three columns C1, C2, and C3 with values 1, 7, and 4, respectively. The query:
   SELECT GREATEST (C1, C2, C3) FROM T1
returns 7.

If column C3 has a value of null instead of 4, the same query returns the null value.