VeloDB Cloud
SQL Reference
SQL Functions
Scalar Functions
Conditional Functions
LEAST

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

ParameterDescription
<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 returns NULL.

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                                                        |
+----------------------------------------------------------------------------+