Why can't we use LIMIT?


  • 0
    S

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


  • 0

    Hi,

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


    select
    IF(@Sal=null,null,@Sal) as MySalary
    from
    (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
    Y

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

    Check my accepted answer
    https://discuss.leetcode.com/topic/76008/accepted-solution


Log in to reply
 

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