Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Fetch n-th row from the end of a table in T-SQL
declare @whichRow INT
set @whichRow = 5
select top 1 * from
select top (@whichRow) * from <thetable> where <whereclause> order by <orderbyclause> desc
) tmp
order by id asc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment