MySQL offset infinite rows

前端 未结 9 2250
星月不相逢
星月不相逢 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 16:53

    I know that this is old but I didnt see a similar response so this is the solution I would use.

    First, I would execute a count query on the table to see how many records exist. This query is fast and normally the execution time is negligible. Something like:

    SELECT COUNT(*) FROM table_name;
    

    Then I would build my query using the result I got from count as my limit (since that is the maximum number of rows the table could possibly return). Something like:

    SELECT * FROM table_name LIMIT count_result OFFSET desired_offset;
    

    Or possibly something like:

    SELECT * FROM table_name LIMIT desired_offset, count_result;
    

    Of course, if necessary, you could subtract desired_offset from count_result to get an actual, accurate value to supply as the limit. Passing the "18446744073709551610" value just doesnt make sense if I can actually determine an appropriate limit to provide.

提交回复
热议问题