SELECT TOP 1 salary
FROM (
SELECT TOP 3 salary
FROM employee_table
ORDER BY salary DESC ) AS emp
ORDER BY salary ASC;
Certainly! To retrieve the third maximum salary from the employee_table
, you can use the following SQL query:
SELECT DISTINCT salary
FROM employee_table
ORDER BY salary DESC
LIMIT 2, 1;
Explanation:
ORDER BY salary DESC
: This sorts the salaries in descending order, so the highest salary comes first.LIMIT 2, 1
: This skips the first two rows (which correspond to the highest and second-highest salaries) and then selects one row. This effectively gives you the third-highest salary.
Note: The DISTINCT
keyword is used to handle cases where there might be duplicate salary values in the table. If duplicate salaries are not possible, you can omit it.