Thursday, March 21, 2019

MySQL query to find the second highest salary

Second maximum salary using sub query and IN clause:


SELECT MAX(salary) FROM employees WHERE salary NOT IN ( SELECT Max(salary) FROM employees);

Second maximum salary using sub query and < operator instead of IN clause:


SELECT MAX(salary) From employees WHERE salary < ( SELECT Max(salary) FROM employees);

Second maximum salary using the LIMIT clause in query:


SELECT salary FROM (SELECT salary FROM employees ORDER BY salary DESC LIMIT 2) AS Emp ORDER BY salary LIMIT 1;

No comments:

Post a Comment