Forum Moderators: coopster
I want to spread the contents of my MySQL DB over different pages(i.e. page 1,2,etc).
First I thought I could use LIMIT 0,9 and then on the next page LIMIT 9,18. Although this works, I also need to have it ordered using the ORDER BY statement.
From the documentation I read the LIMIT X statement only considers the first X results found from the WHERE clause(so, the ORDER BY statement only orders the already retrieved X results, instead of the whole result).
So, I need to return the first 9 results from the ordered results of the MySQL query.
What is the most efficient way to do this?
I could create different tables, each one ordered by some criterium but this creates quite some redundancy.
I hope you can help me :)
Rest assured, MySQL will
SELECTyour records first,
ORDERthem, then take the
LIMIT.
You are probably reading How MySQL Optimizes LIMIT [dev.mysql.com] which lets you in on some of the internal workings of MySQL. Basically, it is saying that, yes, I am going to sort your result set in the order you requested, but as I start the order sorting, I'm going to keep in mind your limitations and apply them at the same time and stop as soon as I meet your needs.
Thanks, ergophobe ;)