Results 1 to 8 of 8

Thread: How to get 6th heghest salary?

  1. #1
    Junior Member
    Join Date
    Mar 2008
    Answers
    24

    Question How to get 6th heghest salary?

    In SQL Server 2005, How to get 6th highest salary from a table?


    Regards,
    Prashanth Chenna.


  2. #2
    Contributing Member
    Join Date
    Jun 2007
    Answers
    65

    Re: How to get 6th heghest salary?

    There are already few posts for ur question. You can get your reply from here
    http://http://www.geekinterview.com/...st-salary.html

    ---V V---
    Vikas Vaidya


  3. #3
    Contributing Member
    Join Date
    Apr 2008
    Answers
    31

    Re: How to get 6th heghest salary?

    You can use the Query as fallowed

    SELECT * FROM T1 WHERE n=
    (SELECT COUNT(DISTINCT ) FROM T2 WHERE T1. <=T1.)

    where 'n' is the nth highest value for the in the .


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

    Thumbs up Re: How to get 6th heghest salary?

    select top 1 salary
    from (select distinct top 6 salary from employee order by salary desc) a
    order by salary


  5. #5
    Contributing Member
    Join Date
    Apr 2008
    Answers
    31

    Re: How to get 6th heghest salary?

    Hi jrameshvjr,

    your query will give the only one record, if there are many number of employees holding the same salary then it won't be applicable..


  6. #6
    Junior Member
    Join Date
    Sep 2008
    Answers
    2

    Re: How to get 6th heghest salary?

    select * from emp where salary not in (select distinct top n-1 salary from emp order by salary desc)

    n=number of highest salary


  7. #7
    Junior Member
    Join Date
    Mar 2008
    Answers
    2

    Smile Re: How to get 6th heghest salary?

    select top 1 emp_salary from (select top 6 emp_salary from tblemployee order by emp_salary desc) a order by emp_salary asc


  8. #8
    Junior Member
    Join Date
    Nov 2008
    Answers
    3

    Re: How to get 6th heghest salary?

    select top(6) from tablename,but this will not applicable where there more number of employees drawing the same salary? it includes duplicate rows


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