How to find the employee whose salary is second highest?
EMP_ID | EMP_NAME | SALARY |
---|---|---|
1 | Sachin | 50000 |
2 | Virat | 65000 |
3 | Rohit | 40000 |
4 | Hardik | 55000 |
For example, in above table, “Hardik” has the second highest salary as 55000.
Below is simple query to find the employee whose salary is highest.
SELECT name, MAX(salary) as salary FROM employee;
We can use above query to find the second largest salary by nesting it.
SELECT name, MAX(salary) AS salary FROM employee WHERE salary < (SELECT MAX(salary) FROM employee);