©SQL :: Manager
HomeProgram InformationTechnical detailsFree downloadDonate for a cup of coffee
myway SQL Manager for MySQL and MariaDB, Download on Uptodown
SQL functionMySQLMariaDB

The GREATEST SQL Function in MySQL and MariaDB - Largest value from list

GREATESTSyntax:GREATEST(%, %)
Return value:Depending on the data types used
Function type:Comparison function
Function Description

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11

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: Download

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.
FROM_DAYSFROM_UNIXTIMEGET_FORMATGREATESTGROUP_CONCATHEXHOUR

Further MySQL und MariaDB SQL Comparison functions

COALESCECOALESCE(%, %)
More about COALESCE Function

DECODE_ORACLEDECODE_ORACLE()
More about DECODE_ORACLE Function

INTERVALINTERVAL(%, %)
More about INTERVAL Function

IFIF(Expression, Value1, Value2)
More about IF Function

LEASTLEAST(%, %)
More about LEAST Function

STRCMPSTRCMP(String 1, String 2)
More about STRCMP Function

Numeric functionsString functionsRegular ExpressionsDate and Time functions
Comparison functionsEncryption & CompressionConversion functionsNULL functions
Aggregate functionsWindow functionsJSON functionsGeometric functions
Sequence functionsInformation functionsDynamic ColumnsMiscellaneous functions
More information about the GREATEST SQL function: mysql.com and mariadb.com and w3schools.com
Updated: 2023-09-24ImprintContactTerms & conditionsPrivacy & CookiesUpdatesSitemapFacebookLinkedinTwitterStatistics©2020-2024 Heino Cunze-Fischer