🚀✅ Easy Solution with two liner code 🏆
Please Upvote my solution, if you find it helpful ;)\n\n# Intuition\nThe intuition behind the approach is to retrieve the Nth highest salary from the "Employee"
## ***Please Upvote my solution, if you find it helpful ;)***\n\n# Intuition\nThe intuition behind the approach is to retrieve the Nth highest salary from the "Employee" table. To achieve this, we first subtract 1 from N to adjust it to the correct index. Then, we query the distinct salaries from the "Employee" table, order them in descending order, and use the LIMIT and OFFSET clauses to select the Nth highest salary. This approach ensures that we retrieve the desired result efficiently.\n\n# Approach\n1. We start by subtracting 1 from the given input N. This is because the problem assumes 1-based indexing, but SQL uses 0-based indexing.\n\n1. Next, we write a MySQL query using the SELECT statement to retrieve distinct salaries from the Employee table. The DISTINCT keyword ensures that each salary value is considered only once.\n\n1. We order the salaries in descending order using the ORDER BY clause. This means that the highest salary will appear first in the result set.\n\n1. Finally, we use the LIMIT clause to restrict the result to only the Nth row, starting from the 0-based index N. Since we subtracted 1 from N earlier, this will give us the Nth highest salary.\n# Complexity\n- Time complexity:\nThe time complexity of your solution depends on the efficiency of executing the SQL query. The query retrieves distinct salaries and sorts them, which typically has a time complexity of $$O(n log n)$$, where n is the number of rows in the Employee table.\n\n- Space complexity:\nThe space complexity of your solution is determined by the size of the result set. Since you are retrieving a single salary, the space complexity is $$O(1)$$ or constant.\n\n# Code\n```\nCREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT\nBEGIN\nSET N = N-1;\n  RETURN (\n      # Write your MySQL query statement below.\n        SELECT DISTINCT(salary) from Employee order by salary DESC\n      LIMIT 1 OFFSET N\n  );\nEND\n```\n## ***Please Upvote my solution, if you find it helpful ;)***\n![6a87bc25-d70b-424f-9e60-7da6f345b82a_1673875931.8933976.jpeg](https://assets.leetcode.com/users/images/546be381-7a0d-415f-9815-dc4523f5a8a4_1687718638.7967603.jpeg)\n
['Database', 'MySQL']