I was given the below question to solve.
What I tried:
- I thought to join all the three tables together. But I'm facing challenges in getting the maximum salary for each department.
select e.empName, d.deptName
from employee e
join department d on e.deptId = d.deptId
join salary s on e.empId = s.EmpId
where s.salary = (select max(salary) from salary s)
group by d.deptid;
I referred these answers also but I'm not able to implement them according to my needs.
- join-multiple-columns-from-one-table-to-single-column-from-another-table
- sql-select-only-rows-with-max-value-on-a-column
- select-emp-with-max-sal-from-each-dept
This is my sql fiddle link. I am using MYSQL version 5.6 SQL FIDDLE
Any suggestions would be helpful.