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
orders| amount |
|---|
| 1200 |
| 900 |
| 1500 |
| 700 |
Run result
| max_amount |
|---|
| 1500 |
Common issues
No. COUNT(*) counts rows, while COUNT(column) ignores rows where that column is NULL.
No. They return aggregate values only; use a join, ordering, or a window function when you need the complete row.
Put source-row predicates in WHERE and aggregate-result predicates in HAVING.
Tags
Was this explanation clear?
Thanks. This feedback will inform the next content review.