ajay singh yadav ajay singh yadav - 11 months ago 71
SQL Question

How to get depatment wise max salary as well as name of employee having it?

I have table like this.

enter image description here
I want to find the max salary department wise and the name of employee who has it.
I ran MySql query

select concat(First_name,' ',Last_name) as Name,max(SALARY)
from Employee
group by Department;

which gives result as shown below.

enter image description here

In which max(SALARY) is correct but Emplyoee name is wrong.How to get both correct?


Try this:

SELECT concat(First_name,' ',Last_name) as Name,SALARY FROM Employee WHERE salary IN (SELECT MAX(SALARY) FROM Employee GROUP BY Department);

this will help you.