Skip to content

SQL MAX Function

Syntax

The MAX function in SQL is used to find the maximum value of a column.

-- Find the maximum value in a column
SELECT MAX(column1)
FROM table_name;
-- Find the maximum value for each group
SELECT column2, MAX(column1)
FROM table_name
GROUP BY column2;

Example

-- Find the maximum salary of all employees
SELECT MAX(salary)
FROM employees;
/* Output:
| MAX(salary) |
|-------------|
| 60000 |
*/
-- Find the maximum salary for each department
SELECT department, MAX(salary)
FROM employees
GROUP BY department;
/* Output:
| department | MAX(salary) |
|-------------|-------------|
| Sales | 50000 |
| Marketing | 40000 |
| HR | 60000 |
*/