DB2 Version 9.7 for Linux, UNIX, and Windows

LEAST scalar function

Read syntax diagramSkip visual syntax diagram
                         V               |      

The schema is SYSIBM.

The LEAST function returns the minimum 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 smallest 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 LEAST scalar function is a synonym for the MIN scalar function.


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

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