MYSQL subquery, easy to understand
\nselect d.name as department,e.name as employee,salary\nfrom department d\njoin employee e\non d.id = e.departmentid\nwhere (departmentid,salary ) in\n(select 
```\nselect d.name as department,e.name as employee,salary\nfrom department d\njoin employee e\non d.id = e.departmentid\nwhere (departmentid,salary ) in\n(select departmentid,max(salary) from employee group by departmentid);\n```\nBreaking the code\n\n1 inside the subquerry, we can get the max salary for each department using the \n```\n(select departmentid,max(salary) from employee group by departmentid)\n```\n\n2 select the multiple condtion where clause to select the max salary by department using \n```\nwhere (departmentid,salary ) in\n(select departmentid,max(salary) from employee group by departmentid)\n```\n\n3  Rest of the code is to join the tables and select the required column\n\nupvote if helps, ping if need help.
['MySQL']