Select a row and rows around it

后端 未结 7 2128
庸人自扰
庸人自扰 2020-12-19 15:05

Ok, let\'s say I have a table with photos.

What I want to do is on a page display the photo based on the id in the URI. Bellow the photo I want to have 10 thumbnails

7条回答
  •  醉梦人生
    2020-12-19 15:51

    I resolve this by using the below code:

    SELECT  A.* FROM  (
       (
          SELECT  *  FROM gossips
          WHERE id < 7
          ORDER BY id DESC
          LIMIT 2
       )
      UNION
       (
          SELECT * FROM gossips
          WHERE id > 7
          ORDER BY id ASC
          LIMIT 2
       )
    
     ) as A
    ORDER BY A.id
    

提交回复
热议问题