SQL – MAX
Retrieve the maximum (largest) value in a column using the MAX() aggregate function.
Table of Contents
MAX() is the mirror of MIN() — it returns the largest value in a column. Use it to find the top score, most expensive product, latest date, or the last alphabetical entry. Like all aggregate functions, it ignores NULLs and collapses the result to a single value unless combined with GROUP BY.
A practical pattern: use MIN() and MAX() together to understand the range of your data. The gap between them tells you how spread out your values are — an early but crucial step in data analysis.
Finding range
SELECT MIN(score) AS floor,
MAX(score) AS ceiling,
MAX(score) - MIN(score) AS range
FROM students;
Try It Yourself — Interactive SQL Editor
Edit the query below and click Run Query ▶ to see live results powered by SQLite running directly in your browser.
Key Points
- MAX returns the single largest value in a column
- MAX of a date column returns the most recent date
- MAX of a string column returns the last alphabetically
- Combine MIN and MAX to quickly understand data spread
Pro Tip from CodesCompiler: The best way to learn SQL is to break things intentionally — modify the query above, change the WHERE conditions, try different columns. Every error teaches you something the docs cannot.
In the next lesson, we continue exploring SQL’s powerful feature set to build your database mastery.