CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
RETURN (
SELECT DISTINCT Salary FROM Employee ORDER BY Salary DESC LIMIT N-1,1
);
END
this query gives exception when M=0 as it becomes -1 however when I write it like
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
DECLARE M INT;
SET M=N-1;
RETURN (
SELECT DISTINCT Salary FROM Employee ORDER BY Salary DESC LIMIT M,1
);
END
Please explain the difference between the two statements. When I set M= N-1 , m will also be negative when N=0 it gives following exception
Line 6: SyntaxError: near '-1,1
);
END'
My answer Thanks for @George Hayward