The GREATEST()
function returns the greatest value from a list of arguments.
Figure 1 shows a visual representation of the GREATEST()
function.
GREATEST(arg1, arg2, .... argn)
The GREATEST()
function takes n number of arguments as a parameter.
Arguments can be of any data type, such as integer, float, string, etc.
The GREATEST()
function returns the greatest 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 greatest value, then this function will return the first occurring greatest value.
-- NULL as argumentSELECT GREATEST(NULL,10,3,4,6,9);-- integers as argumentSELECT GREATEST(5,10,3,4,6,9);-- floats as argumentsSELECT GREATEST(4.9,4.6,4.5,4.2,4.1);-- strings as argumentSELECT GREATEST('educative', 'edpresso');-- mixture of strings and integer-- first '10' and '0' will be casted as integer and then comparison is doneSELECT GREATEST('10',1,'0');