Getting row before and after a query

前端 未结 5 2022
失恋的感觉
失恋的感觉 2021-01-16 20:15

I currently have this query

SELECT  short_url,
        type,
        file_thumbnail,
        file_embed,
        media.id,
        user,
        media.file_u         


        
5条回答
  •  一生所求
    2021-01-16 20:53

    You can use subqueries to get the id of the previos and next record:

    ...
    where media.id in (
      '$id',
      (select max(id) from media where id < '$id'),
      (select min(id) from media where id > '$id')
    )
    ...
    

提交回复
热议问题