I found a solution for finding the n(th) highest salary from the web :
SELECT * FROM Employee Emp1
WHERE (N-1) = (
SELECT COUNT(DISTINCT(Emp2.Salary))
FROM Employee Emp2
WHERE Emp2.Salary > Emp1.Salary
)
But I am unable to understand how the query is actually being executed, i.e. how the query is processing at each step, especially in the subquery where multiple alias of same table occur ->
WHERE Emp2.Salary > Emp1.Salary
And what is the comparison operator doing with this-
WHERE (N-1) = <subquery>
Can someone please help me out with it?