MySQL solution using [ORDER BY & LIMIT] | Easy Step-by-Step Explanation
\nCREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT\nBEGIN\n\nDECLARE M INT;\nSET M=N-1;\n  RETURN (\n      # Write your MySQL query statement below.\n    
```\nCREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT\nBEGIN\n\nDECLARE M INT;\nSET M=N-1;\n  RETURN (\n      # Write your MySQL query statement below.\n      SELECT DISTINCT salary FROM Employee\n      ORDER BY salary DESC\n      LIMIT M,1\n\n\n);\nEND\n```\n\n**Explanation:**\n```\nSELECT DISTINCT salary FROM Employee\n```\n* First I have selected **DISTINCT salary** from **Employee** table. \n\n```\nORDER BY salary DESC\nLIMIT M,1\n```\n* After that I have used **ORDER BY** on **salary** in **DESCENDING ORDER**.\n* Then I have used **LIMIT** to show only the **Nth Highest Salary** using **M variable**\n\n\n```\nDECLARE M INT;\nSET M=N-1;\n```\n* Here I have declared a new integer **M**, that will be used in **the LIMIT clause** for returning the nth highest salary.
['MySQL']