MySQL solution featuring the DISTINCT keyword
Solution is as follows:\n\nCREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT\nBEGIN\n  SET n = N-1;\n  RETURN (\n    SELECT MAX(salary) FROM ( SELECT DISTI
Solution is as follows:\n```\nCREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT\nBEGIN\n  SET n = N-1;\n  RETURN (\n    SELECT MAX(salary) FROM ( SELECT DISTINCT salary FROM Employee ORDER BY salary DESC LIMIT 1 OFFSET n ) AS max_filtered_salary\n  );\nEND\n```\nThis solution composes of 2 main parts, being just setting a variable and a return query utilizing that variable to select one value from a modified ```Employee``` list. ```n``` is set to be equal to ```N-1``` to be used as an offset when selecting one ```salary``` value from the modified ```Employee``` table, which only contains entries that have a unique ```salary``` and which has its entries sorted by their ```salary``` in descending order. Modifying this list as such and selecting a single offset value yields the N\'th maximum value in the table ```Employee```. Using ```N``` as it is without setting a variable that\'s one less causes the selected value to always be one after the correct answer due to offsetting starting at 0 and ```N``` starting at 1.
['MySQL']