MLUG: Re: [MLUG - DISCUSSION] random db results?
Re: [MLUG - DISCUSSION] random db results?
Email address obfuscation in effect -- please click here to turn it off.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
On Wed, Jul 03, 2002 at 07:21:15AM -0500, Michael wrote:
> Does anyone know how to ask for random results from a db? Something like:
> 
> 'SELECT id FROM files WHERE view = 0 GROUP BY random LIMIT 25'
> 
> 

MySQL seems to have a RAND() function:

 "You can't use a column with RAND() values in an ORDER BY clause,
 because ORDER BY would evaluate the column multiple times. In MySQL
 Version 3.23, you can, however, do: SELECT * FROM table_name ORDER BY
 RAND() This is useful to get a random sample of a set SELECT * FROM
 table1,table2 WHERE a=b AND c<d ORDER BY RAND() LIMIT 1000. Note that a
 RAND() in a WHERE clause will be re-evaluated every time the WHERE is
 executed. RAND()  is not meant to be a perfect random generator, but
 instead a fast way to generate ad hoc random numbers that will be
 portable between platforms for the same MySQL version."

http://www.mysql.com/doc/M/a/Mathematical_functions.html
-- 
Michael Procter
EMAIL:PROTECTED
--
To unsubscribe, go to http://mlug.missouri.edu/members/edit.php

Archives are available at http://mlug.missouri.edu/list-archives/