Thursday, January 19, 2017

Find out second highest salary with sql subquery

In this table  where we see some employee salary data .If we have to find out second highest salary. how we find it ? Now we do a query that find out the second highest salary .Suppose table name employees.This are data of this employees table.


E_ID
E_Salary
1
10000
2
20000
3
30000






Query: 

SELECT MAX(E_Salary) FROM Employees
WHERE E_Salary NOT IN (SELECT MAX(E_Salary) FROM Employees )

Output:


20000

No comments:

Post a Comment