Register Login

SQL Query to find highest salary of employee in each department

Updated Jun 07, 2019

How to Get the Highest Salary of Each Department?

Hi All,

Could you please help me to get the highest salary for each department. If multiple employees having the highest salary in the same department then I need the get oldest employee details(who joined first in the company).

SOLUTION

Please use the SQL Query below in order to get the highest salary of department:

SELECT DepartmentID, MAX(Salary) 
FROM Employee  
GROUP BY DepartmentID

Now for Printing the name, you must join the Employee table with Department table using key DepartmentID,

SELECT DepartmentName, MAX(Salary) 
FROM Employee e RIGHT JOIN Department d ON e.DepartmentId = d.DepartmentID 
GROUP BY DepartmentName

 


Comments

  • 30 Jul 2015 3:06 pm Sugandh

    select * from (select ename,deptno,sal,hiredate,dense_rank() over(partition by deptno order by sal desc,hiredate asc) rn from emp)
    where rn=1;

  • 15 Apr 2017 11:34 pm Guest

    SELECT DEPARTMENT_ID,MAX(SALARY) FROM EMPLOYEES GROUP BY DEPARTMENT_ID;

     


×