Anteoy
Anteoy

Reputation: 31

mysql limit offset, result is disordered

I have a table which have 31M data,when I try like this:

select id from class limit 20 offset 0;

I got the result is not ordered,the result like this "13,18273785,29046580...",why it's not "1,2,3,4,...,20"?

Btw,at another small table,I got the correct result which like "1,2,2,4,...,20",The normal table has less than 10,000 rows of data,The incorrect table has more than 30000,000 rows of data.Any idea? Because mysql transaction isolation mechanism? thanks

I know I can use the order by to get the data I expected,why in the table which have a bit of data like 3000 rows,the limit and offset can get the data I expected,but the another table 30,000,000 can not get ordered

Upvotes: 1

Views: 50

Answers (1)

Darshan Mehta
Darshan Mehta

Reputation: 30809

You need to add ORDER BY clause e,g,:

SELECT id 
FROM class 
ORDER BY id
LIMIT 20 OFFSET 0;

Upvotes: 1

Related Questions