Click here to Skip to main content
15,880,972 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SQL
Find the 2nd maximum salary for every department.

  SELECT TOP(1) SALARY
FROM  EMPLOYEES
WHERE SALARY IN( SELECT DISTINCT TOP(2) SALARY FROM EMPLOYEES
                 -- GROUP BY SALARY,DNO
                  ORDER BY  SALARY desc
                )
GROUP BY DNO,SALARY


I am unable to get the correct answer
Posted
Comments
Thanks7872 5-Feb-15 7:46am    
Use google for correct answer : https://www.google.co.in/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=second%20highest%20salary%20in%20sql

1 solution

This question gets asked with every new intake at college and has been answered here many many times ... pick your favourite from this selection of answers[^] on CodeProject
 
Share this answer
 
Comments
TheRealSteveJudge 5-Feb-15 8:12am    
Exactly! 5*

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900