✅MySQL-2 Different Approach ||Easy understanding|| Beginner level|| Simple, Short ,Solution✅
Please upvote to motivate me in my quest of documenting all leetcode solutions. HAPPY CODING:)\nAny suggestions and improvements are always welcome.\n____\n\u27
***Please upvote to motivate me in my quest of documenting all leetcode solutions. HAPPY CODING:)\nAny suggestions and improvements are always welcome**.*\n______________________\n\u2705 **MySQL Code :**\n***Approach 1:***\n```\nSELECT t1.Department, t1.Employee, t1.Salary\nFROM(SELECT d.name AS Department, e.name AS Employee, e.salary AS Salary\n,RANK()OVER(PARTITION BY d.id ORDER BY salary DESC) AS rk\nFROM Department AS d\nJOIN Employee AS e ON E.departmentId = d.id) AS t1\nWHERE rk = 1\n```\n__________________________________\n***Approach 2***:\n\n```\nSELECT D.Name AS Department ,E.Name AS Employee ,E.Salary \nFROM\n\tEmployee E,\n\t(SELECT DepartmentId,max(Salary) as max FROM Employee GROUP BY DepartmentId) T,\n\tDepartment D\nWHERE E.DepartmentId = T.DepartmentId \n  AND E.Salary = T.max\n  AND E.DepartmentId = D.id\n```\n______________________\nIf you like the solution, please upvote \uD83D\uDD3C\nFor any questions, or discussions, comment below. \uD83D\uDC47\uFE0F
['MySQL']