Second max

  • i have used a query to get the second max from a list of sal like this:-

    select sal from emptab where empid in (2,4,7) and rownum = 2 order by sal desc;

    the problem is that the rownum is not working, can anyone suggest how to get second max value from a list of values?

  • I guess this is an Oracle query?

    In SQL Server you need to use the ROW_NUMBER function and sort in the OVER clause.

    In an outer query you can select the row with row number equal to 2.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply