SQL course menu
SQL MAX(): Find the Largest Value (Numbers, Dates and Text)
Learn the SQL MAX function: the highest number, latest date, or last text value, MAX per group, the range between MIN and MAX, and how to find the row that holds the maximum.
On this page
MAX returns the largest value in a column: the highest salary, the most recent order, the most expensive product. It works exactly like MIN, in the opposite direction.
The example tables#
employees
orders
Highest number and latest date#
SELECT MAX(salary) AS highest
FROM employees;highest
-------
81000SELECT MAX(order_date) AS last_order
FROM orders;last_order
----------
2026-03-02For text, MAX returns the value that sorts last alphabetically.
MAX per group#
Each customer's biggest order:
SELECT customer_id, MAX(amount) AS biggest_order
FROM orders
GROUP BY customer_id
ORDER BY customer_id;customer_id | biggest_order
------------+--------------
1 | 250
2 | 560
5 | 90MIN and MAX together#
Aggregates can be combined in one query and in calculations. The spread between the highest and lowest salary:
SELECT MIN(salary) AS lowest,
MAX(salary) AS highest,
MAX(salary) - MIN(salary) AS salary_range
FROM employees;lowest | highest | salary_range
-------+---------+-------------
46000 | 81000 | 35000Who has the maximum?#
As with MIN, find the value first and then the rows that match:
SELECT name, salary
FROM employees
WHERE salary = (SELECT MAX(salary) FROM employees);name | salary
------+-------
Meera | 81000"The highest-paid person in each department" is a harder version of this question. It needs a correlated subquery or a window function, which you will learn in ROW_NUMBER and RANK.
NULL values#
MAX ignores NULLs and returns NULL when there is nothing to compare.
Common mistakes#
Practice#
Practice exercise
Using products (name, category, price), return the most expensive price in each category, highest first.
Show hint
MAX(price) with GROUP BY category, ordered descending.
Show solution
SELECT category, MAX(price) AS most_expensive
FROM products
GROUP BY category
ORDER BY most_expensive DESC;category | most_expensive
------------+---------------
Electronics | 55000
Furniture | 7000
Stationery | 60Key takeaway#
Finished this lesson?