QUERY DOUBTgreenspun.com : LUSENET : DBAzine : One Thread
IF I HAVE A NUMBER OF RECORDS SAY A COMPANY'S SALARY DETAILS.HOW CAN I RETRIEVE SECOND HIGHEST SALARY BY MEANS OF SQL QUERY
-- ILAYARAJA (email@example.com), May 22, 2004
The following query selects the second maximum salary from the employee table. The number 2 can be replaced with n to get the 'n'th maximum salary.
SELECT MAX(SALARY) FROM EMPLOYEE A WHERE 2 > (SELECT COUNT(DISTINCT(SALARY)) FROM EMPLOYEE B WHERE A.SALARY > B.SALARY) ;
Hope this helps.
-- Krishna Kumar (firstname.lastname@example.org), July 28, 2004.