LEAST function

The LEAST function returns the minimum value in a set of values.

LEAST Function

LEAST( ,expression expression)

The arguments must be compatible and each argument must be an expression that returns a value of any data type other than complex types, BYTES, TEXT, BLOB, CLOB, or a user-defined type based on any of these types. The user-defined type must implement the support function lessthan() in order to use the LEAST function. The selected argument is converted, if necessary, to the data type of the result. The result data type is determined by all the operands and the compatibility rule is consistent with CASE expression.

The result of the function is the smallest argument value. If at least one argument can be null, the result is null. If LEAST is used to compare dates, the return value is the earliest date.

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

SELECT LEAST (C1, C2, C3) FROM T1

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