Re: MySQL: Top $num results

From: Date: Sun, 13 Feb 2005 17:43:46 +0000
Subject: Re: MySQL: Top $num results
References: 1 2 3 4 5 6  Groups: php.db 
Request: Send a blank email to php-db+get-38571@lists.php.net to get a copy of this message
ioannes wrote:
"If you use LIMIT row_count with ORDER BY, MySQL ends the sorting as soon as it has found the first row_count lines rather than sorting the whole table. " http://dev.mysql.com/doc/mysql/en/limit-optimization.html I need to get the top $num results from a completely sorted table (eg sorted on ID, ie the $num latest inserted rows). Which functions should I be considering?
LIMIT works that way, the write-up is just confusing. If you "ORDER BY id DESC LIMIT 10", then you'll get the 10 highest values of "id" in the result. The write-up just means that MySQL isn't going to bother sorting the rest of the table after it finds the 10 highest (or whatever your limit is). Is that what you're after? -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals – www.phparch.com

« previous php.db (#38571) next »