We have an employee salary table, how do we find the second highest from it.

Below Sql Query find the second highest salary

SELECT * FROM pcdsEmployeeSalary a WHERE (2=(SELECT COUNT(DISTINCT(b.salary)) FROM pcdsEmployeeSalary b WHERE b.salary>=a.salary))

To find the second highest salary from an employee salary table in a Database Management System (DBMS), you can use a query like this:

sql
SELECT MAX(salary) AS second_highest_salary
FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);

This query first finds the maximum salary in the table using MAX(salary). Then, it finds the maximum salary that is less than the overall maximum salary using the subquery (SELECT MAX(salary) FROM employees). Finally, it selects the maximum salary that satisfies this condition, which is the second highest salary in the table.