MySQL select before after row

前端 未结 4 1322
北荒
北荒 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:59

    Try this:

    select * from test where callValue = 'val3'  
    union all  
    (select * from test where callValue < 'val3' order by id desc limit 1) 
    union all  
    (select * from test where callValue > 'val3' order by id asc limit 1) 
    

    or

    select * from test where id = 8
    union all  
    (select * from test where id < 8 order by id desc limit 1) 
    union all  
    (select * from test where id > 8 order by id asc limit 1) 
    

提交回复
热议问题