LEAST
Descriptionβ
Compares multiple expressions and returns the smallest value among them. If any parameter is NULL
, the function returns NULL
.
Syntaxβ
LEAST(<expr> [, ...])
Parametersβ
Parameter | Description |
---|---|
<expr> | The expressions to be compared. Supported types include TINYINT , SMALLINT , INT , BIGINT , LARGEINT , FLOAT , DOUBLE , STRING , DATETIME , and DECIMAL . |
Return Valueβ
- Returns the smallest value among the given expressions.
- If any parameter is
NULL
, the function returnsNULL
.
Examplesβ
SELECT LEAST(-1, 0, 5, 8);
+--------------------+
| LEAST(-1, 0, 5, 8) |
+--------------------+
| -1 |
+--------------------+
SELECT LEAST(-1, 0, 5, NULL);
+-----------------------+
| LEAST(-1, 0, 5, NULL) |
+-----------------------+
| NULL |
+-----------------------+
SELECT LEAST(6.3, 4.29, 7.6876);
+--------------------------+
| LEAST(6.3, 4.29, 7.6876) |
+--------------------------+
| 4.29 |
+--------------------------+
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 |
+----------------------------------------------------------------------------+