Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

How to get the 5th highest salary from the table. Suppose, I have 100 rows and I want to display details of 5th highest salary of the individual then how to write that query in T-SQL using SQL Server 2008R2.

1 emp1 1000
2 emp2 2000
3 emp3 3000
4 emp4 4000
5 emp5 5000
6 emp6 6000
7 emp7 7000
8 emp8 8000
9 emp9 9000
share|improve this question

closed as not a real question by Paul White, Mat, dezso, Jon Seigel, RolandoMySQLDBA May 8 '13 at 15:03

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

6  
What should happen on ties? –  ypercube May 8 '13 at 6:10
2  
This a bad question. Will everyone have different salaries? How at ties handled at places 1-4+ At 5+? Is is DENSE_RANK or RANK you want? –  gbn May 8 '13 at 10:31
add comment

1 Answer 1

with salaryCTE AS
 (
 select ROW_NUMBER() over(order by AnnualSalary desc) AS Ranking,*
 from salary -- employe salary table
  )
 select * from salaryCTE where Ranking=5
share|improve this answer
3  
how about ties? Use DENSE_RANK() instead. –  Remus Rusanu May 8 '13 at 5:41
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.