Why can't we use LIMIT?

  • 0

    Like SELECT Salary FROM Employee ORDER BY Salary ASC LIMIT 1,1;

  • 0


    I improved on your query.
    Pls try the below query.

    IF(@Sal=null,null,@Sal) as MySalary
    (select @Sal:=(select distinct (Salary) as SecondHighestSalary from Employee order by Salary Desc limit 1,1)) variables

    As you can notice there were 3 issues in ur query.
    namely you used asc instead of desc.
    Secondly if no return is returned you are not returning null (I think so).
    Thirdly, using distinct you will pick only single value if many people are contenders for the second largest salary.

  • 0

    Sure you can use LIMIT but you need to give your result an alias "SecondHighestSalary" to pass the system.

    Check my accepted answer

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.