GREATEST vs LEAST
GREATEST method returns greatest number from list of given numbers.
GREATEST(value 1,value 2,....,value n);
LEAST method returns least number from list of given numbers.
LEAST(value 1,value 2,....,value n);
Example
GREATEST(29,38,10,45); //Returns 45
LEAST(4,5,3,28); //Returns 3
|
-- Returns 28
SELECT GREATEST(2,3,4,1,28);
-- Returns NULL if list contains NULL
SELECT GREATEST(3,6,8,NULL,2);
-- Returns 3
SELECT LEAST(6,3,7,4);
-- Returns NULL if list contains NULL
SELECT LEAST(6,3,NULL,2,1);
|
Hints
If any one of the item value is NULL then GREATEST and LEAST methods are returning NULL.
|