Results 1 to 7 of 7

Thread: nth highest salary

  1. #1
    Junior Member
    Join Date
    Nov 2007
    Answers
    2

    nth highest salary

    how to retrieve nth highest salary from an emp table


  2. #2
    Expert Member
    Join Date
    Apr 2007
    Answers
    500

    Re: nth highest salary

    select level, max('col_name') from my_table
    where level = '&n'
    connect by prior ('col_name') > 'col_name')
    group by level;

    example to find 4th highest salary

    select level, max(sal) from emp
    where level=4
    connect by prior sal > sal
    group by level


  3. #3
    Moderator
    Join Date
    Jun 2007
    Answers
    2,074

    Re: nth highest salary

    You can also try
    Code:
    select max(sal) from emp where sal< (select max(sal) from emp where sal<(select max(sal) from emp))
    This one using nested sub sub query. In this way you select maximum upto 255 level.


  4. #4
    Junior Member
    Join Date
    Nov 2007
    Answers
    3

    Re: nth highest salary

    select sal from (

    (select distinct sal from emp where rownum<=&n order by sal desc )

    )
    where rownum <=1 order by sal


  5. #5
    Junior Member
    Join Date
    Nov 2007
    Answers
    2

    Thumbs up Re: nth highest salary

    Quote Originally Posted by veluru13 View Post
    how to retrieve nth highest salary from an emp table
    thank u friends for ur replies.


  6. #6
    Contributing Member
    Join Date
    Sep 2007
    Answers
    35

    Re: nth highest salary

    for this we can give the rank for each salary.first highest sal is rank 1 so on.

    here is the eg:

    select a.ename,a.sal,b.rnk from emp a,(select rank() over(order by sal desc
    nulls last) rnk from emp) b where b.rnk=&rnk;


  7. #7

    Re: nth highest salary

    select emp_name,sal from (
    select emp_name, sal, rank() over (order by sal desc nulls last ) rn from emp) where rn= &var


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact