Skip to main content

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 DECIMAL types.

Optional Parameters

  • Supports multiple arguments.

Return Value

  • Returns the smallest value among the given expressions.
  • If any argument is NULL, returns NULL.

Usage Notes

  1. 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
  2. If any argument is NULL, the result will be NULL.

Examples

  1. Example 1
    SELECT LEAST(-1, 0, 5, 8);
    +--------------------+
    | LEAST(-1, 0, 5, 8) |
    +--------------------+
    | -1 |
    +--------------------+
  2. NULL argument
    SELECT LEAST(-1, 0, 5, NULL);
    +-----------------------+
    | LEAST(-1, 0, 5, NULL) |
    +-----------------------+
    | NULL |
    +-----------------------+
  3. Type conversion
    SELECT LEAST(6, 9.29, 7);
    +-------------------+
    | LEAST(6, 9.29, 7) |
    +-------------------+
    | 6.00 |
    +-------------------+

    The first argument "6" is converted to Decimal type.

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