MAX

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

Read syntax diagramSkip visual syntax diagramMAX(expression ,expression )

The arguments must be compatible. Character-string arguments are compatible with datetime values. The arguments cannot be DataLink or XML values.

expression
An expression that returns the value of any built-in numeric or string data type. If one of the arguments is numeric, then character and graphic string arguments are cast to numeric before evaluating the function.

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 one of the arguments is null.

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

If a collating sequence other than *HEX is in effect when the statement is executed and the arguments are SBCS data, mixed data, or Unicode data, the weighted values of the strings are compared instead of the actual values. The weighted values are based on the collating sequence.

Note

Start of changeSyntax alternatives: GREATEST can be specified as a synonym for MAX.End of change

Examples

  • Assume the host variable M1 is a DECIMAL(2,1) host variable with a value of 5.5, host variable M2 is a DECIMAL(3,1) host variable with a value of 4.5, and host variable M3 is a DECIMAL(3,2) host variable with a value of 6.25.
      SELECT MAX(:M1,:M2,:M3)
        FROM SYSIBM.SYSDUMMY1
    Returns the value 6.25.
  • Assume the host variable M1 is a CHARACTER(2) host variable with a value of 'AA', host variable M2 is a CHARACTER(3) host variable with a value of 'AA ', and host variable M3 is a CHARACTER(4) host variable with a value of 'AA A'.
      SELECT MAX(:M1,:M2,:M3)
        FROM SYSIBM.SYSDUMMY1
    Returns the value 'AA A'.