Showing posts with label SqlQueries. Show all posts
Showing posts with label SqlQueries. Show all posts

Wednesday, January 5, 2011

How do you find the Second highest Salary?


How do you find the Second highest Salary?
This is the most common question asked in Interviews.
EMPLOYEE table has fields EMP_ID and SALARY how do you find the second highest salary?
Answer:
We can write a sub-query to achieve the result
SELECT MAX(SALARY) FROM EMPLOYEE WHERE SALARY NOT IN (SELECT MAX(SALARY) FROM EMPLOYEE)