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

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

    I'm not sure about any of the rest, but I know SQLite and MySQL don't have any "default" row ordering. In those two dialects, at least, the following snippet grabs the 15th entry from the_table, sorting by the date/time it was added:

    SELECT * FROM the_table ORDER BY added DESC LIMIT 1,15
    

    (of course, you'd need to have an added DATETIME field, and set it to the date/time that entry was added...)

提交回复
热议问题