Function Reference

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;
MAX(unit_price)
66000

Latest birth date by status

MySQL 8.1
SELECT status,
	MAX(birthday) AS latest_birthday
FROM FamilyMembers
GROUP BY status;
statuslatest_birthday
father1961-09-11
mother1968-09-06
son1983-06-05
daughter2005-01-13

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.

See also

Where to learn