MAX() in MySQL — How It Works
What the MySQL MAX() function does, with an example.
Published October 21, 2026
MAX() returns the largest value in a column for numbers, strings or dates, ignoring NULL.
How it works
Often used to find the latest date or highest id.
Try it in MySQL
SELECT MAX(price) FROM products
999.00
SELECT MAX(created_at) FROM orders
2026-11-12 13:00:00
SELECT user_id, MAX(score) FROM scores GROUP BY user_id
best score per user
Practical examples
Example 1
SELECT MAX(price) FROM products;
-- 999.00Example 2
SELECT MAX(created_at) FROM orders;
-- 2026-11-12 13:00:00Example 3
SELECT user_id, MAX(score) FROM scores GROUP BY user_id;
-- best score per userUse it in a real query
SELECT MAX(price) FROM products;Common mistakes
- Selecting non-aggregated columns with MAX.
- Using MAX(id)+1 to generate ids (race conditions).
- NULL on empty tables.
Key takeaways
- MAX() in one line: MAX() returns the largest value in a column for numbers, strings or dates, ignoring NULL.
- Try queries in a test database first.
- Check NULL handling and data types.
FAQ
Get the full row?
ORDER BY col DESC LIMIT 1 or a join on the max value.
Does MAX() work in other databases?
Most have an equivalent, but names and syntax vary between MySQL, PostgreSQL, SQL Server and SQLite.