1Find the second highest salary.
Three standard answers; know at least two.
-- 1. Subquery
SELECT MAX(salary) AS second_highest
FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);
-- 2. DENSE_RANK (generalises to Nth highest, handles ties)
SELECT DISTINCT salary FROM (
SELECT salary, DENSE_RANK() OVER (ORDER BY salary DESC) AS r FROM employees
) t WHERE r = 2;
-- 3. LIMIT / OFFSET
SELECT DISTINCT salary FROM employees ORDER BY salary DESC LIMIT 1 OFFSET 1;Mention edge cases: ties at the top (use DISTINCT or DENSE_RANK), and returning NULL when there is no second salary (the MAX version does that naturally). For "highest salary per department", add PARTITION BY department_id.