MySQL query to find the highest salary from each department

In article we will explain how to write a MySQL query to find the highest salary from each department from the employees table.

Read Also : Find The Nth Highest Employee Salary From An Employee Table In MySql

Find the highest salary from each department

Let’s create a simple example of employees table. We will populate this table with id, name, salary and department of employees.

SELECT * FROM employees;
idnamesalarydepartment
1Tom4000Technology
2Sam6000Sales
3Bob3000Technology
4Alen8000Technology
5Jack12000Marketing
6Charlie8000Human Resources
7Harry6000Marketing
8Jacob4000Human Resources

The following MySQL statement find the maximum salary from each department, you will be required to use the GROUP BY clause with the SELECT query.

SELECT department, MAX(salary)  
FROM employees 
GROUP BY department
ORDER BY MAX(salary) DESC;
departmentMAX(salary)
Marketing12000
Human Resources8000
Technology8000
Sales6000
1 Comment
  1. Braintree Tyres says

    I think what you wrote was actually very logical.

Leave A Reply

Your email address will not be published.