SQLPathLab
Aggregation · Basic

MAX

finding the maximum value.

Overview

MAX returns the largest non-NULL input and can operate on numbers, dates, and text according to collation. It returns only the maximum expression, not the other columns from the row containing it. Use ordering with LIMIT, a window function, or a join when the complete row is required. With GROUP BY, each group receives its own maximum.

Basic syntax

SELECT MAX(amount) AS max_amount FROM orders;

Examples

MAX example

Read the largest orders.amount value and verify it against the sample maximum of 1500.

Sample table

Table:orders
orders
amount
1200
900
1500
700

Run result

result
max_amount
1500

Common issues

Are COUNT(*) and COUNT(column) the same?

No. COUNT(*) counts rows, while COUNT(column) ignores rows where that column is NULL.

Do MAX and MIN return the rest of the source row?

No. They return aggregate values only; use a join, ordering, or a window function when you need the complete row.

Where should filters go around aggregation?

Put source-row predicates in WHERE and aggregate-result predicates in HAVING.

Tags

Aggregation

Was this explanation clear?