For the complete documentation index, see llms.txt. This page is also available as Markdown.

LEAST

Return the smallest of two or more values. The arguments are compared as integers, reals, or strings depending on context, and NULL is returned if any is NULL.

Syntax

LEAST(value1,value2,...)

Description

With two or more arguments, returns the smallest (minimum-valued) argument. The arguments are compared using the following rules:

  • If the return value is used in an INTEGER context or all arguments are integer-valued, they are compared as integers.

  • If the return value is used in a REAL context or all arguments are real-valued, they are compared as reals.

  • If any argument is a case-sensitive string, the arguments are compared as case-sensitive strings.

  • In all other cases, the arguments are compared as case-insensitive strings.

LEAST() returns NULL if any argument is NULL.

Invalid temporal arguments are an exception. An argument such as DATE('') returns NULL when selected on its own. Inside LEAST(), it is compared the same way as with the other comparison operators:

  • A string that cannot be read as a date, such as '' or 'abc', is compared as the zero date '0000-00-00'.

  • A date with an impossible day, such as '2026-02-30', is compared as written.

Such an argument does not make the result NULL. The result is NULL only if the chosen value is not a valid date in the current SQL mode. For example, '0000-00-00' is not valid when NO_ZERO_DATE is set.

Examples

DATE('') is NULL on its own, but LEAST() compares it as the zero date:

An argument that is actually NULL makes the result NULL:

This page is licensed: GPLv2, originally from fill_help_tables.sql

spinner

Last updated

Was this helpful?