Does LIMIT OFFSET,LENGTH require ORDER BY for pagination?

前端 未结 2 808
南旧
南旧 2020-12-20 12:48

I have a MyISAM table with 28,900 entires. I\'m processing it in chunks of 1500, which a query like this:

SELECT * FROM table WHERE id>0 LIMIT $iStart,150         


        
相关标签:
2条回答
  • 2020-12-20 12:54

    You should use ORDER BY to ensure a consistent order. Otherwise the DBMS may return rows in an arbitrary order (however, one would assume that it's arbitrary but consistent between queries if the no rows are modified).

    0 讨论(0)
  • 2020-12-20 12:59

    Like pretty much every other SQL engine out there, MySQL MyISAM tables make no guarantees at all about the order in which rows are returned unless you specify an ORDER BY clause. Typically the order they are returned in will be the order they were read off the filesystem in, which can change from query to query depending on updates, deletes, and even the state of cached selects.

    If you want to avoid having the same row returned more than once then you must order by something, the primary key being the most obvious candidate.

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