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

后端 未结 30 2546
执笔经年
执笔经年 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:38

    select * from 
    (select * from ordered order by order_id limit 100) x order by 
    x.order_id desc limit 1;
    

    First select top 100 rows by ordering in ascending and then select last row by ordering in descending and limit to 1. However this is a very expensive statement as it access the data twice.

提交回复
热议问题