Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to find out 3rd max salary from an emp table?

 
saikrishna cinux
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please can any one provide me an easy understandable query for finding out 3rd max salary from emp table?

thanks in advance



saikrishna
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This query should work for oracle.

Select * From (Select * From Emp Order by Salary desc ) where RowId = 3
 
saikrishna cinux
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry it's not working oracle sql

any other queries please
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this



Shailesh
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't test, but this may work. It is finding the max value in the table, and then finding the max value that is less than that, and doing it one more time again. Note if the 3rd highest value has the max value too this query wouldn't indicate that. That may or may not be what you want.



With sybase (and possibly other db's) you could use set rowcount, and order by desc. The 3rd row would be your value.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic