Select a row and rows around it

后端 未结 7 2160
庸人自扰
庸人自扰 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:34

    If you're happy to use temp tables, your original query could be broken down to use them.

    SELECT
        *
    FROM media
    WHERE id < 7
    ORDER BY id DESC
    LIMIT 0, 4
    INTO TEMP t1;
    
    INSERT INTO t1
    SELECT
       *
    FROM media
    WHERE id >= 7
    ORDER BY id ASC
    LIMIT 0, 6;
    
    select * from t1 order by id;
    drop table t1;
    

提交回复
热议问题