MySQL offset infinite rows

前端 未结 9 2240
星月不相逢
星月不相逢 2020-11-22 16:25

I would like to construct a query that displays all the results in a table, but is offset by 5 from the start of the table. As far as I can tell, MySQL\'s LIMIT

9条回答
  •  清歌不尽
    2020-11-22 17:04

    You can use a MySQL statement with LIMIT:

    START TRANSACTION;
    SET @my_offset = 5;
    SET @rows = (SELECT COUNT(*) FROM my_table);
    PREPARE statement FROM 'SELECT * FROM my_table LIMIT ? OFFSET ?';
    EXECUTE statement USING @rows, @my_offset;
    COMMIT;
    

    Tested in MySQL 5.5.44. Thus, we can avoid the insertion of the number 18446744073709551615.

    note: the transaction makes sure that the variable @rows is in agreement to the table considered in the execution of statement.

提交回复
热议问题