MySQL select before after row

前端 未结 4 1330
北荒
北荒 2020-12-15 08:28

This is the example table:

Column             | 1st record | 2nd record | 3rd record | 4th record | etc
id (primary) | 1 | 5
4条回答
  •  难免孤独
    2020-12-15 08:45

    Once you have the id 8, you should be able to do a variation on:

    select * from mytable
    where id < 8
    order by id desc
    limit 1
    

    and:

    select * from mytable
    where id > 8
    order by id asc
    limit 1
    

    for the previous and next record.

提交回复
热议问题