Try something like:
SELECT TOP 1 compensation FROM (
SELECT TOP 2 compensation FROM employees
ORDER BY compensation DESC
) AS em ORDER BY compensation ASC
Essentially:
- Find the top 2 salaries in descending order.
- Of those 2, find the top salary in ascending order.
- The selected value is the second-highest salary.
If the salaries aren't distinct, you can use SELECT DISTINCT TOP ...
instead.