Results 1 to 10 of 10

Thread: How to display 3rd highest salary to 5th highest salary from emp table

  1. #1
    Junior Member
    Join Date
    Apr 2008
    Answers
    4

    Thumbs up How to display 3rd highest salary to 5th highest salary from emp table

    Hi,
    could any one please tell me how to display the higest salaries in between two numbers.
    suppose say...display from 2nd highest salary to 5th highest salary from a table.
    please clarify this


  2. #2
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    Re: How to display 3rd highest salary to 5th highest salary from emp table

    >>display from 2nd highest salary to 5th highest salary from a table
    here is the query
    select ename,job,sal
    from
    (
    select rownum rn,ename,job,sal
    from
    ( select * from emp order by sal desc )
    )
    where rn between 2 and 5;
    -- where rn between lowerbound and upperbound


  3. #3
    Junior Member
    Join Date
    Feb 2009
    Answers
    8

    Re: How to display 3rd highest salary to 5th highest salary from emp table

    hi

    You can take the help of inline query and rowid to solve these types of queries.
    The query below may help you

    select rownum,ename,salary
    from (select ename,salary
    from employee
    order by salary desc)
    where rownum between 3 and 5;


  4. #4
    Contributing Member
    Join Date
    Dec 2008
    Answers
    76

    Re: How to display 3rd highest salary to 5th highest salary from emp table

    Try this..

    select empname, salary
    from (select empname, salary, dense_rank() over(order by salary) d_rank
    from emp)
    where d_rank in (3,4,5);


  5. #5
    Expert Member
    Join Date
    Nov 2008
    Answers
    300

    Re: How to display 3rd highest salary to 5th highest salary from emp table

    Check this:

    Code:
    SQL> select empno,salary,row_number() OVER(ORDER BY salary DESC) rn from emp;
    
         EMPNO     SALARY         RN
    ---------- ---------- ----------
             9         90          1
             8         80          2
             6         60          3
             4         40          4
             3         30          5
             2         20          6
             1         10          7
    
    7 rows selected.
    
    SQL> ed
    Wrote file afiedt.buf
    
      1  SELECT x.empno,salary FROM
      2  (select empno,salary,row_number() OVER(ORDER BY salary DESC) rn from emp) x
      3* WHERE rn >= &lower_limit AND rn <= &upper_limit
    SQL> /
    Enter value for lower_limit: 2
    Enter value for upper_limit: 5
    old   3: WHERE rn >= &lower_limit AND rn <= &upper_limit
    new   3: WHERE rn >= 2 AND rn <= 5
    
         EMPNO     SALARY
    ---------- ----------
             8         80
             6         60
             4         40
             3         30
    
    SQL>



  6. #6
    Junior Member
    Join Date
    Jul 2010
    Answers
    5

    Re: How to display 3rd highest salary to 5th highest salary from emp table

    Hi,

    Here is the solution.

    SELECT salary
    FROM employee
    ORDER BY salary DESC LIMIT 2, 3


    I hope this will help you....


  7. #7
    Junior Member
    Join Date
    Apr 2011
    Answers
    1

    Re: How to display 3rd highest salary to 5th highest salary from emp table

    select salary from emp_table order by salary asc limit 2,3;


  8. #8
    Junior Member
    Join Date
    Apr 2011
    Answers
    3

    Re: How to display 3rd highest salary to 5th highest salary from emp table

    If use MS SQL database
    It should be

    select top 4 salary from employees where salary!=(select max(salary) from employees) order by salary desc


  9. #9

    Re: How to display 3rd highest salary to 5th highest salary from emp table

    select e.* from(select empname,sal,dense_rank()
    over(order by sal desc) rank from emp) e
    where e.rank>=3 and e.rank<=5;


  10. #10

    Re: How to display 3rd highest salary to 5th highest salary from emp table

    we can get the solution for this queiry using 4 ways ...among 4 one solution is this
    Quote Originally Posted by Ramadurga Prasad View Post
    select e.* from(select empname,sal,dense_rank()
    over(order by sal desc) rank from emp) e
    where e.rank>=3 and e.rank<=5;



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