Selecting nth highest salary

Discussion in 'Databases' started by sscheral, Jul 24, 2008.

  1. #1
    Selecting nth highest salary in bellow query change the number
    6 to any position then it gives highest salary of that position -1
    means if it 6 then it gives 7th highest salary
    if it 4 then it gives 5th highest and so on.

    select salary from emp e
    where 6 = ( Select count(distinct(sal)) from emp e1 where e.sal < e1.sal)



    -- selects nth highest salary bellow ine picks 6th highest salary
    select Top 1 sal from emp where sal in(Select Top 6 sal from emp order by desc) order by sal ASC

    select MIN(sal) from emp where sal in(Select Top 6 sal from emp order by desc)


    :)
     
    sscheral, Jul 24, 2008 IP