Thread: Order by rand()
View Single Post
Old 06-11-2008, 02:18 PM   #9 (permalink)
buggabill
The Contributor
 
buggabill's Avatar
 
Join Date: Jan 2008
Location: Maine, USA
Posts: 92
Thanks: 2
buggabill is on a distinguished road
Default

That is why it is cpu intensive. RAND() will execute every time the WHERE clause does which will once for every record that would be returned regardless of the LIMIT.

From what I gather/understand/whatever, RAND will assign a random number to all the rows that fit the criteria and then order the results by those numbers.

The full query still needs to run even though you have the LIMIT in there, because you are ordering the results. Only the top 4 will be returned.
__________________
-- Bill
"Why is it drug addicts and computer aficionados are both called users?" -Clifford Stoll
buggabill is offline  
Reply With Quote