LEAST
Description
Compares multiple expressions and returns the smallest value among them. If any argument is NULL, returns NULL.
Syntax
LEAST(<expr> [, ...])
Parameters
Required Parameter
- <expr>: Supports- TINYINT,- SMALLINT,- INT,- BIGINT,- LARGEINT,- FLOAT,- DOUBLE,- STRING,- DATETIME, and- DECIMALtypes.
Optional Parameters
- Supports multiple arguments.
Return Value
- Returns the smallest value among the given expressions.
- If any argument is NULL, returnsNULL.
Usage Notes
- It is recommended to pass arguments of the same type. If argument types differ, the function will attempt to convert them to the same type. For conversion rules, refer to: Type Conversion
- If any argument is NULL, the result will be NULL.
Examples
- Example 1
SELECT LEAST(-1, 0, 5, 8);+--------------------+
 | LEAST(-1, 0, 5, 8) |
 +--------------------+
 | -1 |
 +--------------------+
- NULL argument
SELECT LEAST(-1, 0, 5, NULL);+-----------------------+
 | LEAST(-1, 0, 5, NULL) |
 +-----------------------+
 | NULL |
 +-----------------------+
- Type conversion
SELECT LEAST(6, 9.29, 7);+-------------------+
 | LEAST(6, 9.29, 7) |
 +-------------------+
 | 6.00 |
 +-------------------+The first argument "6" is converted to Decimal type. 
- Date type
SELECT LEAST('2022-02-26 20:02:11', '2020-01-23 20:02:11', '2020-06-22 20:02:11');+----------------------------------------------------------------------------+
 | LEAST('2022-02-26 20:02:11', '2020-01-23 20:02:11', '2020-06-22 20:02:11') |
 +----------------------------------------------------------------------------+
 | 2020-01-23 20:02:11 |
 +----------------------------------------------------------------------------+