MAX scalar function

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

Read syntax diagramSkip visual syntax diagramMAX(expression ,expression )

The schema is SYSIBM.

expression
An expression that returns a value of any built-in data type or user-defined data type that is comparable with data type of the other arguments. The data type cannot be a LOB, distinct type base on a LOB, XML, array, cursor, row, or structured type.

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

The selected argument is converted, if necessary, to the attributes of the result. The attributes of the result are determined by the data types of all the arguments as explained in Rules for result data types.

Notes

  • The MAX scalar function is a synonym for the GREATEST scalar function.
  • The MAX function cannot be used as a source function when creating a user-defined function. Because this function accepts any comparable data types as arguments, it is not necessary to create additional signatures to support user-defined data types.

Example

Return the bonus for an employee, the greater of 500 and 5% of the employee's salary.
   SELECT EMPNO, MAX(SALARY * 0.05, 500)
     FROM EMPLOYEE