3 Solutions|dense_rank()|Limit|Comparison
1st Approach\n\nLimit\n\nSort the salary in descending order apply the limit N-1,1(where N-1 from where to select the salary and 1 represent to select one Salar
**1st Approach**\n\n**Limit**\n\nSort the salary in descending order apply the limit N-1,1(where N-1 from where to select the salary and 1 represent to select one Salary.\n\n\n```\nCREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT\nBEGIN\n  SET N = N - 1;\n  RETURN (\n      SELECT DISTINCT SALARY FROM EMPLOYEE ORDER BY SALARY DESC LIMIT N, 1\n      \n  );\nEND\n```\n\n\n**2nd Approach**\n\n**Dense Rank**\n\nDense Rank is used for give priority to salary, we will give highest priority to highest salary and select *Nth* highest priority will be our *Nth* highest salary.\n\n```\nCREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT\nBEGIN\n  # SET N = N - 1;\n  RETURN (\n      select distinct(salary) from (select salary,dense_rank() over (order by salary desc) as ds from employee) as temp where ds=N\n      \n  );\nEND\n```\n\n**3rd Approach**\n\n**Compare table data with its own duplicate**\n\nwe will take one salary and compare it with all the salary if there will be N-1 salary which are greater than selected salary then that will be our *Nth* highest salary.\n\n```\nCREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT\nBEGIN\n  RETURN (\n      # Write your MySQL query statement below.\n      select distinct(e1.salary) from employee e1 where N-1=(select count(distinct salary) from employee e2 where e2.salary>e1.salary)\n  );\nEND\n```\n\n\n**NOTE :- Salary will be return null itself if there will be no Nth highest Salary.**
['MySQL']