MySQL GREATEST() Function

In MySQL, the GREATEST() function returns the largest value in the parameter list. If you want to find the smallest value in he parameter list, use the LEAST() function.

GREATEST() Syntax

Here is the syntax of MySQL GREATEST() function:

GREATEST(param1, param2, ..., paramN)

Parameters

param1, param2, ..., paramN
Required. Argument list for comparison. They can be any data type, or expressions.

Return value

In MySQL, the GREATEST() function returns the largest value in the parameter list.

If any of the parameters is NULL, the function will return NULL.

GREATEST() Examples

SELECT
    GREATEST(2, 1, 5),
    GREATEST(2, 1, 5, '0'),
    GREATEST('a', 'b', 'c'),
    GREATEST('Hello', 'World'),
    GREATEST('a', 'b', NULL)\G

output

*************************** 1. row ***************************
         GREATEST(2, 1, 5): 5
    GREATEST(2, 1, 5, '0'): 5
   GREATEST('a', 'b', 'c'): c
GREATEST('Hello', 'World'): World
  GREATEST('a', 'b', NULL): NULL