SQL SERVER – 2005 – Find Nth Highest Record from Database Table – Using Ranking Function ROW_NUMBER

I have previously written SQL SERVER – 2005 – Find Nth Highest Record from Database Table where I have shown query to find 4th highest record from database table. Everytime when I write blog I am always very eager to read comments of readers. Some of regular readers are industry leaders and and their comments always teach us all something new. One of them is Nicholas Paldino [.NET/C# MVP]. He has always provided valuable solution and comments to this blog. His recent comment about finding Nth Highest Record is quite an interesting.

USE AdventureWorks
GO
SELECT
t.*
FROM
(
SELECT
e1.*,
row_number() OVER (
ORDER BY e1.Rate DESC) AS _Rank
FROM
HumanResources.EmployeePayHistory AS e1
) AS t
WHERE
t._Rank = 4

Reference : Pinal Dave (https://blog.sqlauthority.com) , Nicholas Paldino [.NET/C# MVP]

MVP, SQL Function, SQL Joins, SQL Scripts
Previous Post
SQL SERVER – How to Retrieve TOP and BOTTOM Rows Together using T-SQL – Part 3
Next Post
SQL SERVER – FIX : Error : 3702 Cannot drop database because it is currently in use – Part 2

Related Posts

Leave a Reply