In MySQL, how can I retrieve ALL rows in a table, starting from row X? For example, starting from row 6:
LIMIT 5,0
This returns nothing, so I tried this:
LIMIT 5,ALL
Still no results (sql error).
I'm not looking for pagination functionality, just retrieving all rows starting from a particular row. LIMIT 5,2000
seems like overkill to me. Somehow Google doesn't seem to get me some answers. Hope you can help.
Thanks
If you're looking to get the last x number of rows, the easiest thing to do is
SORT DESC
and LIMIT to the first x rows. Granted, theSORT
will slow your query down. But if you're opposed to setting an arbitrarily large number as the secondLIMIT
arg, then that's the way to do it.I think you don't need to enter max value for select all by LIMIT. It is enough to find count of table and then use it as max LIMIT.
The next query should work too, and is in my opinion more effective...
By ordering the query will find the id imediately and skip this one, so the next rows he won't check anymore whether the id = 1.
According to the documentation:
This is the maximum rows a MyISAM table can hold, 2^64-1.
The only solution I am aware of currently is to do as you say and give a ridiculously high number as the second argument to LIMIT. I do not believe there is any difference in performance to specifying a low number or a high number, mysql will simply stop returning rows at the end of the result set, or when it hits your limit.