MAX

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



All but the first argument can be parameter markers. There must be two or more arguments.

Each argument must be an expression that returns a value of any built-in data type other than a CLOB, DBCLOB, BLOB, ROWID, or XML.

Character string arguments and binary string arguments cannot have a length attribute greater than 32704, and graphic string arguments cannot have a length attribute greater than 16352.

The arguments are evaluated in the order in which they are specified. The result of the function is the maximum argument value.

The selected argument is converted, if necessary, to the attributes of the result. If the MAX function has more than two arguments, the rules are applied to the first two arguments to determine a candidate result type. The rules are then applied to that candidate result type and the third argument to determine another candidate result type. This process continues until all arguments are analyzed and the final result type and CCSID is determined.

Notes

Syntax alternatives:
GREATEST is a synonym for MAX.

Example 1:

The following example selects the maximum value among the values in the SALARY column from the table EMPLOYEE.

SELECT MAX(SALARY) FROM EMPLOYEE

The above example returns 75000.