How to select the nth row in a SQL database table?

后端 未结 30 2883
执笔经年
执笔经年 2020-11-22 06:06

I\'m interested in learning some (ideally) database agnostic ways of selecting the nth row from a database table. It would also be interesting to see how this can b

30条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-22 06:34

    Nothing fancy, no special functions, in case you use Caché like I do...

    SELECT TOP 1 * FROM (
      SELECT TOP n * FROM 
      ORDER BY ID Desc
    )
    ORDER BY ID ASC
    

    Given that you have an ID column or a datestamp column you can trust.

    提交回复
    热议问题