MySQL: select 5 rows before and after specific row

后端 未结 5 516
陌清茗
陌清茗 2020-12-20 23:26

I have table called \"users\" and need to select 2 rows before and after specific row, sorted by users.score ASC

users table (structure):

id     name         


        
5条回答
  •  旧巷少年郎
    2020-12-21 00:29

    Perhaps using union all

    (
     select * from users where id < 5 order by score limit 2
    )
    union all
    (
      select * from users where id > 5 order by score limit 2
    )
    

提交回复
热议问题