The LEAST()
function returns the smallest value from a list of arguments.
Figure 1 shows a visual representation of the LEAST()
function.
LEAST(arg1, arg2, .... argn)
The LEAST()
function takes n number of arguments as a parameter.
Arguments can be of any data type, such as integer, float, string, etc.
The LEAST()
function returns the smallest value from the list of arguments sent as a parameter.
- If any argument is
NULL
, then this function will returnNULL
.- If the arguments are a mixture of integers and strings, then this function will compare them as numbers.
- If any argument is a non-binary string, then this function will compare all the arguments as non-binary strings.
- If two or more arguments have the smallest value, then this function will return the first occurring smallest value.
-- NULL as argumentSELECT LEAST(NULL,10,3,4,6,9);-- integers as argumentSELECT LEAST(5,10,3,4,6,9);-- floats as argumentsSELECT LEAST(4.9,4.6,4.5,4.2,4.1);-- strings as argumentSELECT LEAST('educative', 'edpresso');-- mixture of strings and integer-- first '10' and '11' will be casted as integer and then comparison is doneSELECT LEAST('10',1,'11');