3
Reply

Find the second maximum record in a SQL Table/ Temp Table?

    SELECT MAX (Income)
    FROM Employee
    WHERE Salary NOT IN (SELECT Max (Income)
    FROM Employee);

    ;WITH CTE
    AS
    (
    SELECT ROW_NUMBER() OVER(ORDER BY Income DESC) ROW_NUM, Income
    FROM Employee
    )

    SELECT Income FROM CTE WHERE ROW_NUM = 2

    select * from (select sal, dense_rank()over(order by sal desc)rank from tempemp) Where rank=2;. -- you can change the rank value -- example if you need 5th max record then rank=5