MySQL offset infinite rows

前端 未结 9 2130
星月不相逢
星月不相逢 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:12

    As noted in other answers, MySQL suggests using 18446744073709551615 as the number of records in the limit, but consider this: What would you do if you got 18,446,744,073,709,551,615 records back? In fact, what would you do if you got 1,000,000,000 records?

    Maybe you do want more than one billion records, but my point is that there is some limit on the number you want, and it is less than 18 quintillion. For the sake of stability, optimization, and possibly usability, I would suggest putting some meaningful limit on the query. This would also reduce confusion for anyone who has never seen that magical looking number, and have the added benefit of communicating at least how many records you are willing to handle at once.

    If you really must get all 18 quintillion records from your database, maybe what you really want is to grab them in increments of 100 million and loop 184 billion times.

    0 讨论(0)
  • 2020-11-22 17:13

    From the MySQL Manual on LIMIT:

    To retrieve all rows from a certain offset up to the end of the result set, you can use some large number for the second parameter. This statement retrieves all rows from the 96th row to the last:

    SELECT * FROM tbl LIMIT 95, 18446744073709551615;
    
    0 讨论(0)
  • 2020-11-22 17:13

    As others mentioned, from the MySQL manual. In order to achieve that, you can use the maximum value of an unsigned big int, that is this awful number (18446744073709551615). But to make it a little bit less messy you can the tilde "~" bitwise operator.

      LIMIT 95, ~0
    

    it works as a bitwise negation. The result of "~0" is 18446744073709551615.

    0 讨论(0)
提交回复
热议问题