Re: MySQL rand() is slow on large datasets
I found that Jay solution gave a result set that were to close together. For example I would get rows from 7100 - 7150. That was not random enough for me. So here is what I did to get more random of rows with out killing the speed of Jay's query.
SELECT * FROM Table T JOIN (SELECT MAX(ID) AS ID FROM Table) AS x ON T.ID >= FLOOR(x.ID*RAND()) LIMIT 10;
Edited 1 time(s). Last edit at 05/21/2008 02:39PM by Jeff Fillmore.
Subject
Views
Written By
Posted
19309
July 24, 2007 08:19AM
14662
July 24, 2007 08:28AM
8034
September 02, 2007 10:30AM
10443
January 18, 2008 12:25AM
Re: MySQL rand() is slow on large datasets
7902
May 15, 2008 03:15PM
8838
May 12, 2009 10:21AM
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.