CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT BEGIN DECLARE result INT; SET result = NULL; SET N = N - 1; SELECT DISTINCT salary INTO result FROM Employee ORDER BY salary DESC LIMIT 1 OFFSET N; RETURN ( result ); END
Link
SELECT DISTINCT( SELECT DISTINCT salary FROM Employee e ORDER BY salary DESC LIMIT 1 OFFSET 1 ) AS SecondHighestSalary;