Translate

Sunday, 6 March 2016

SQL Query to second find highest salary of Employee

n= 0 for first record salary
n = 1 second highest salary 
n= 2 third highest salary 

SELECT DISTINCT(Salary) FROM Employees ORDER BY Salary DESC LIMIT n,1


Also some other queries 

select MAX(Salary) from Employee WHERE Salary NOT IN (select MAX(Salary) from Employee ); 


SELECT salary  FROM (SELECT DISTINCT(salary) FROM Employees ORDER BY salary DESC LIMIT 2) AS emp ORDER BY salary LIMIT 1;

1 comment: