| Author |
sql query
|
Ayub ali khan
Ranch Hand
Joined: Oct 20, 2005
Posts: 378
|
|
Could any one help me how to write a query to find the second largest salary and second smallest salary from a salary table? Thanks in advance!!
|
SCEA part I,TOGAF Foundation
|
 |
Jussi Taimiaho
Ranch Hand
Joined: Mar 01, 2004
Posts: 40
|
|
Two approaches come to my mind. First is to order by salaray and take the next row. Limit the number of rows output, database permitting. Second using subquery, which definately is not the most efficient way, but allows this to be done with a single query. 2nd:
|
 |
Ayub ali khan
Ranch Hand
Joined: Oct 20, 2005
Posts: 378
|
|
|
Thanks Jussi!! Could you metion the query for the first approach?
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26207
|
|
The first one:
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
Ayub ali khan
Ranch Hand
Joined: Oct 20, 2005
Posts: 378
|
|
Thank you v.Much Jeanne!! please pardon my ignorance. From your answer I understood that you sorted the table. What would be the query to retrieve the second largest sal from the sorted table?
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26207
|
|
Ayub, That is correct I sorted the table. The SQL query is what I provided in the above post. To get the second row:
|
 |
Ayub ali khan
Ranch Hand
Joined: Oct 20, 2005
Posts: 378
|
|
Thank you Jeanne!! I understood the logic. Your help is very much appreciated
|
 |
 |
|
|
subject: sql query
|
|
|