MySQL Forums
Forum List  »  Newbie

Re: What would be faster?
Posted by: Thomas Baggelaar
Date: July 23, 2007 08:56AM

This query:

SELECT * FROM `table` WHERE id >= (SELECT FLOOR( MAX(id) * RAND()) FROM `table` ) ORDER BY id LIMIT 1;

should be much faster than this query:

SELECT * FROM `table` ORDER BY RAND() LIMIT 1;

[source: http://akinas.com/pages/en/blog/mysql_random_row]
[source: http://jan.kneschke.de/projects/mysql/order-by-rand]

So why would option 2 in this case be faster?

Options: ReplyQuote


Subject
Written By
Posted
July 23, 2007 05:44AM
Re: What would be faster?
July 23, 2007 08:56AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.