MySQL LEAST() Function
In MySQL, the LEAST()
function returns the smallest value in the parameter list. If you want to find the largest value in a list, use the GREATEST()
function.
LEAST()
Syntax
Here is the syntax of MySQL LEAST()
function:
LEAST(param1, param2, ..., paramN)
Parameters
param1, param2, ..., paramN
- Required. Argument list for comparison. They can be any data type, or expressions.
Return value
In MySQL, the LEAST()
function returns the smallest value in the parameter list.
If any of the parameters is NULL
, the function will return NULL
.
LEAST()
Examples
SELECT
LEAST(2, 1, 5),
LEAST(2, 1, 5, '0'),
LEAST('a', 'b', 'c'),
LEAST('Hello', 'World'),
LEAST('a', 'b', NULL)\G
output
*************************** 1\. row ***************************
LEAST(2, 1, 5): 1
LEAST(2, 1, 5, '0'): 0
LEAST('a', 'b', 'c'): a
LEAST('Hello', 'World'): Hello
LEAST('a', 'b', NULL): NULL
See STRCMP()
function for more details of comparison between strings.