Find nth Salary Without Using Max or Top keyword

Here I am writing SQL query to find nth salary without using top or max keywords. 

SELECT * FROM (

SELECT ROW_NUMBER() OVER (ORDER BY SALARY DESC) AS rownumber,Salary 

FROM Employee ) 

AS foo 

WHERE rownumber = n 


Example
 

SELECT * FROM ( 

SELECT ROW_NUMBER() OVER (ORDER BY SALARY DESC) AS rownumber,Salary 

FROM Employee ) 

AS foo 

WHERE rownumber = 5 

 
The above query will show 5th highest salary from Employee table.

Ebook Download
View all
SQL Jobs
Read by 0 people
Download Now!
Learn
View all