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'

I'm arriving late on this, but I struggled with this problem too. Spent hours debugging this. You could always check for this condition in the
whereclause. Check the query below.The parameters in limit are confusing as well. In some cases
offsetis not supported. There's a simple example for this.We can read the above as
Cheers!