Re: How to find random records in a subset?

From: Date: Fri, 03 Jun 2005 15:25:22 +0000
Subject: Re: How to find random records in a subset?
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-216321@lists.php.net to get a copy of this message
Brian Dunning wrote:
On Jun 3, 2005, at 6:48 AM, Marek Kilimajer wrote:
Brian Dunning wrote:
I am using a routine to find 50 random records in a large MySQL database (about a million records) where I generate a list of 50 random unique ID's,
why can't you use the where condition in the above query?
Because I wouldn't get all 50 records that I need - I'd only get the few out of the 50 that happened to be in the needed subset.
I don't think you get me or I don't get you. Currently you are doing: 1. select id from table order by rand() limit 50 2. select * from table where id in($random_set) right? I meant why not use the where condition in the first query.

« previous php.general (#216321) next »