MS SQL| two approach | subquery| group by | join
Approach 1\n\nselect d.name as Department, e.name as Employee, e.salary as Salary \nfrom Employee e join Department d on e.departmentId = d.id\nwhere 1 > (selec
Approach 1\n```\nselect d.name as Department, e.name as Employee, e.salary as Salary \nfrom Employee e join Department d on e.departmentId = d.id\nwhere 1 > (select count(salary) \n            from Employee e1 \n            where e1.salary > e.salary and e1.departmentId = e.departmentId);\n\n```\n\nApproach 2\n\n```\nselect d.name as Department, e.name as Employee, e.salary as Salary \nfrom Employee e join Department d on e.departmentId = d.id\nwhere e.salary = (select max(salary) \n                from Employee e1 group by e1.departmentId having e1.departmentId = e.departmentId);\n```
['MS SQL Server']