The GREATEST SQL Function in MySQL and MariaDB - Largest value from list |
|
| GREATEST | Syntax: | GREATEST(%, %) | Return value: | Depending on the data types used | Function type: | Comparison function | |
| | The GREATEST() function returns the largest value from a list of any number of arguments.
If the arguments consist of strings and numeric values, GREATEST() returns the largest numeric value.
If any argument in the list has the value NULL, GREATEST() returns NULL.
The opposite function is LEAST(). | SQL Examples for the GREATEST function |
|
select greatest(5, 1, 3, 6, 77);
select greatest(1.01, 1.04, 1.001, 1.0001);
select greatest('Be', 'ac', 'ab', 'aa', 'Ab');
select greatest(5, 1, 3, 6, 'A');
select greatest('Be', 'ac', 'ab', 'aa', 'Ab', 'xx', 65);
select greatest(5, 1, 3, 6, 77, null);
select greatest('Be', 'ac', 'ab', 'aa', 'Ab', null);
|
|
greatest(5, 1, 3, 6, 77) |
int(2) |
77 |
|
|
greatest(1.01, 1.04, 1.001, 1.0001) |
decimal(7) |
1.0400 |
|
|
greatest('Be', 'ac', 'ab', 'aa', 'Ab') |
varchar(2) BINARY |
ac |
|
|
greatest(5, 1, 3, 6, 'A') |
double(23) |
6 |
|
|
greatest('Be', 'ac', 'ab', 'aa', 'Ab', 'xx', 65) |
double(23) |
65 |
|
|
greatest(5, 1, 3, 6, 77, null) |
double(17) |
NULL |
|
|
greatest('Be', 'ac', 'ab', 'aa', 'Ab', null) |
varchar(2) BINARY |
NULL |
|
|
| The examples were created with the MyWAY SQL manager: | How to use the GREATEST() function in MySQL and MariaDB databases | MySQL and MariaDB provide the GREATEST() function, used to determine the maximum value among multiple expressions or values by returning the largest value from the provided list of expressions. Table column names or other expressions can also be used as parameters to obtain the maximum value of, for example, in calculations, comparisons, or when retrieving the maximum 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 GREATEST SQL function: and and |
|
|
|
|