MAX
Returns the largest value of the expression in a group of rows.
MySQL 8.1
MAX(expr)Parameters
- expr
- Expression: a number, string or date
Return value
A value of the same type as expr; strings are compared alphabetically, NULLs are ignored, NULL for an empty set
Examples
Highest price
MySQL 8.1
SELECT MAX(unit_price)
FROM Payments;Latest birth date by status
MySQL 8.1
SELECT status,
MAX(birthday) AS latest_birthday
FROM FamilyMembers
GROUP BY status;Details
Strings are compared as text, even if they contain numbers: the MAX of '9' and '10' is '9'. The function returns only the value; to get the whole row with the maximum, use ORDER BY ... DESC LIMIT 1 or window functions.