*
The moose likes JDBC and the fly likes how to find out 3rd max salary from an emp table? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "how to find out 3rd max salary from an emp table?" Watch "how to find out 3rd max salary from an emp table?" New topic
Author

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

saikrishna cinux
Ranch Hand

Joined: Apr 16, 2005
Posts: 689
please can any one provide me an easy understandable query for finding out 3rd max salary from emp table?

thanks in advance



saikrishna


A = HARDWORK B = LUCK/FATE If C=(A+B) then C=SUCCESSFUL IN LIFE else C=FAILURE IN LIFE
SCJP 1.4
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
This query should work for oracle.

Select * From (Select * From Emp Order by Salary desc ) where RowId = 3


Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
saikrishna cinux
Ranch Hand

Joined: Apr 16, 2005
Posts: 689
sorry it's not working oracle sql

any other queries please
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

Try this



Shailesh


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 860
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.


http://www.jamonapi.com/ - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to find out 3rd max salary from an emp table?
 
Similar Threads
how to select 2nd,3rd or the Nth highest salary from a table in desc or ascen order?
Display the sequence numbers on the output rows of a select in Oracle 10g
Query question
database
scope of alias in subquery