Assume that you are given the following simple database table called Employee that has 2 columns named Employee ID and Salary:
Employee
Employee ID Salary
3 200
4 800
7 450
I want to write a query select max(salary) as max_salary, 2nd_max_salary from the employee.
Then it should return
max_salary 2nd_max_salary
800 450
I know how to find 2nd highest salary
SELECT MAX(Salary) FROM Employee
WHERE Salary NOT IN (SELECT MAX(Salary) FROM Employee )
or to find the nth:
SELECT FROM Employee Emp1 WHERE (N-1) = ( SELECT COUNT(DISTINCT(Emp2.Salary)) FROM Employee Emp2
WHERE Emp2.Salary > Emp1.Salary)
Though I can't unable to figure out how can I join these two results for the desired result.