SQL MAX Function

Quick summary: The SQL MAX() function returns the largest value in a column.

SQL MAX Syntax

SELECT MAX(column_name) FROM table_name WHERE condition
SQL

SQL MAX Basic examples

SELECT MAX(price) FROM products;
SQL
Output:
Highest product price

Finds the maximum numeric value.

SQL MAX Real-world usage

SELECT MAX(created_at) FROM orders;
SQL
Output:
Most recent order date

Finds the latest timestamp.

SQL MAX Edge cases

SELECT MAX(price) FROM products WHERE category_id = 999;
SQL
Output:
NULL

Returns NULL when no rows match.

SQL MAX Common mistakes

Using MAX to fetch full rows

MAX returns a scalar value, not a row.

Incorrect
SELECT * FROM products WHERE price = MAX(price);
Correct
SELECT * FROM products ORDER BY price DESC LIMIT 1;

Use ORDER BY with LIMIT for rows.

SQL MAX Frequently Asked Questions

What does MAX() do in SQL?

Returns the largest value in a column.

Use case of MAX()?

Finding highest values.

Handles NULL?

Ignores NULL values.

Return type?

Same as column type.

Common mistake?

Expecting sorted results.

Works with GROUP BY?

Yes.

Supports strings?

Yes.

Performance?

Fast with indexes.

Used in analytics?

Yes.

Alternative?

ORDER BY DESC LIMIT 1.

Handles dates?

Yes.

Best practice?

Use indexed columns.

SQL MAX Related SQL Keywords