Function Reference

LEAST

Returns the smallest of the given values.

MySQL 8.1
LEAST(value, value[, ...])

Parameters

value
Value to compare: number, string or date

Return value

The smallest value; NULL if any argument is NULL

Examples

Smallest of three numbers

MySQL 8.1
SELECT LEAST(1, 2, -1);
LEAST(1, 2, -1)
-1

Smallest of three strings

MySQL 8.1
SELECT LEAST('apple', 'banana', 'cherry');
LEAST('apple', 'banana', 'cherry')
apple

Comparison with NULL

MySQL 8.1
SELECT LEAST(1, NULL, 3);
LEAST(1, NULL, 3)
<NULL>

Details

Unlike the aggregate function MIN, which finds the minimum across table rows, LEAST compares several values within one row. If the arguments mix numbers and strings, they are compared as strings: LEAST(2, '10') returns '10'.

See also