File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Get Maximum sal from emp table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Get Maximum sal from emp table" Watch "Get Maximum sal from emp table" New topic

Get Maximum sal from emp table

Arjun Palanichamy
Ranch Hand

Joined: Jul 15, 2006
Posts: 51
Hi All..

How to get second maximum sal from emp table... for example

emp sal
=== ====
10 4000
20 1000
30 5000
40 9000
50 6000

from this table i want to get the second maximum sal example data : 50 6000, can you reply anybody...


Thanks in Advance

Martin Simons
Ranch Hand

Joined: Mar 02, 2006
Posts: 196
order by salary and take the second record (or to be exact cycle through the results after the order by and take the second unique value, in order to avoid the first value appearing multiple times).
Perumal Kasi

Joined: Jul 10, 2004
Posts: 12
select max(sal) from emp a where 2=(select count(distinct(sal)) from emp b
where a.sal<=b.sal);
I agree. Here's the link:
subject: Get Maximum sal from emp table
jQuery in Action, 3rd edition