Skip to content
SQLSimplified
aggregate

MAX()

Returns the largest value in a column across a group of rows.

Description

MAX is an aggregate function that returns the largest value found in a column across the rows being aggregated. It works on numbers (highest salary), dates (most recent hire date), and even text (alphabetically last value), making it more versatile than it first appears.

Syntax

MAX(column_name)

Parameters

NameDescriptionOptional
expressionThe column or expression to evaluate. NULL values are ignored when finding the maximum.No

Return Type

MAX returns the same type as the column it's applied to: a numeric column returns a number, a date column returns a date, and so on.

Examples

Employees & Departments

Loading database engine...

Employees & Departments

Loading database engine...

MAX also works on dates and text

MAX(hire_date) returns the most recent hire date, and MAX(last_name) returns the last name that sorts last alphabetically. MAX isn't limited to numbers.

Common Mistakes

  • Assuming MAX only works on numbers. It also works on dates, text, and other orderable types, which is easy to forget.
  • Using MAX to find the whole row with the highest value. MAX(salary) only returns the salary number, not which employee earns it. You need a separate query (like ordering and limiting, or a subquery) to get the full row.
  • Forgetting GROUP BY when a per-category maximum is intended. Without it, MAX collapses the entire table into a single overall maximum.

See also: MIN, AVG, SUM.

Search

Search lessons, functions, examples, and practice problems