The LEAST SQL Function in MySQL and MariaDB - Smallest value from list |
|
| LEAST | Syntax: | LEAST(%, %) | Return value: | Depending on the data types used | Function type: | Comparison function | |
| | The LEAST() function returns the smallest value from a list of any number of arguments.
If the arguments consist of strings and numeric values, LEAST() returns 0.
If any argument in the list has the value NULL, LEAST() returns NULL.
The opposite function is GREATEST(). | SQL Examples for the LEAST function |
|
select least(5, 1, 3, 6, 77);
select least(1.01, 1.04, 1.001, 1.0001);
select least('Be', 'ac', 'ab', 'aa', 'Ab');
select least(5, 1, 3, 6, 77, 'A');
select least('Be', 'ac', 'ab', 'aa', 'Ab', 65);
select least(5, 1, 3, 6, 77, null);
select least('Be', 'ac', 'ab', 'aa', 'Ab', null);
|
|
least(5, 1, 3, 6, 77) |
int(2) |
1 |
|
|
least(1.01, 1.04, 1.001, 1.0001) |
decimal(7) |
1.0001 |
|
|
least('Be', 'ac', 'ab', 'aa', 'Ab') |
varchar(2) BINARY |
Ab |
|
|
least(5, 1, 3, 6, 77, 'A') |
double(23) |
0 |
|
|
least('Be', 'ac', 'ab', 'aa', 'Ab', 65) |
double(23) |
0 |
|
|
least(5, 1, 3, 6, 77, null) |
double(17) |
NULL |
|
|
least('Be', 'ac', 'ab', 'aa', 'Ab', null) |
varchar(2) BINARY |
NULL |
|
|
| The examples were created with the MyWAY SQL manager: | How to use the LEAST() function in MySQL and MariaDB databases | MySQL and MariaDB provide the LEAST() function, used to determine the minimum value among multiple expressions or values by returning the smallest value from the provided list of expressions. Table column names or other expressions can also be used as parameters to obtain the minimum value of, for example, in calculations, comparisons, or when retrieving the minimum value from groups of table columns. The function provides flexibility for multi-value operations. The function returns NULL if any of the provided expressions or values are NULL. | | Further MySQL und MariaDB SQL Comparison functions | |
| | More information about the LEAST SQL function: and and |
|
|
|
|