MAX

Click to skip syntax diagram
Read syntax diagramSkip visual syntax diagram           .-ALL------.
>>-MAX--(--+----------+--expression--)-------------------------><
           '-DISTINCT-'
 

The MAX aggregate function returns the maximum value in a set of values in a group.

expression
The argument values can be any built-in data type other than a DataLink value.

The data type and length attribute of the result are the same as the data type and length attribute of the argument values. When the argument is a string, the result has the same CCSID as the argument.

If a sort sequence other than *HEX is in effect when the statement that contains the MAX function is executed and the arguments are SBCS data, mixed data, or Unicode data, then the result is obtained by comparing weighted values for each value in the set. The weighted values are based on the sort sequence.

The function is applied to the set of values derived from the argument values by the elimination of null values.

The result can be null. If the function is applied to the empty set, the result is a null value. Otherwise, the result is the maximum value in the set.

The specification of DISTINCT has no effect on the result and is not advised.

Examples