MySql | 2 Approaches
Do Upvote, if it Helped :)\n\n\nCREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT\nBEGIN\n  RETURN (\n      \n      # Method 1:\n      \n      select disti
Do Upvote, if it Helped :)\n\n```\nCREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT\nBEGIN\n  RETURN (\n      \n      # Method 1:\n      \n      select distinct salary \n      from employee e1\n      where N = (select count(distinct(e2.salary)) from employee e2 where e2.salary >= e1.salary)\n      \n      # Method 2:\n      \n      select distinct res.salary from (\n          select salary, DENSE_RANK() OVER (ORDER BY salary DESC) as sal_rank from employee \n      ) res \n      where N = res.sal_rank \n      \n      \n  );\nEND\n```
[]