How to find second maximum salary
4 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Malaiah_Reddy
Posted On:   Wednesday, July 7, 2004 03:45 AM

can any one tell me how to find second maximum salary using sql query.

Re: How to find second maximum salary

Posted By:   Sriram_Kanala  
Posted On:   Friday, July 9, 2004 11:18 PM

SELECT * FROM EMPLOYEES E1 WHERE 2 = (SELECT COUNT(*) FROM EMPLOYEES E2 WHERE E1.SALARY <= E2.SALARY)

Re: How to find second maximum salary

Posted By:   David_Thornton  
Posted On:   Wednesday, July 7, 2004 05:26 PM

Use the following SQL statement;



SELECT salary FROM mytable WHERE salary <>
(SELECT MAX(salary) FROM mytable)
ORDER BY salary DESC


the use setMaxRows() to only return 1 row.

Re: How to find second maximum salary

Posted By:   Christopher_Koenigsberg  
Posted On:   Wednesday, July 7, 2004 01:14 PM

somehow I think you are only going to be getting a minimum salary, if you are so incapable of learning simple SQL yourself... :-)

Re: How to find second maximum salary

Posted By:   Simon_Ablett  
Posted On:   Wednesday, July 7, 2004 05:51 AM

The easiest although not necessarily the most efficient approach would be to use something akin to 'SELECT Salary FROM MyTable ORDER BY Salary DESC' and then interate through the resultset noting the first value and then finding the first instance that's not equal to it.

Regards.
About | Sitemap | Contact