Created
December 9, 2016 09:06
-
-
Save tdittmar/052ae4a9813950886995a7ba5aa6d74e to your computer and use it in GitHub Desktop.
Fetch n-th row from the end of a table in T-SQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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