June 25th, 2000, 08:19 AM
The topic almost says it all... I would like to make a SELECT query where the results is returned randomly every time I execute it... ie. one time the entries that starts with B comes first, then the rest... next time I run it I want another letter etc etc... basicly a link rotator... It doesn't have to give even results, ie. standard deviation...
June 25th, 2000, 08:44 AM
In MySQL 3.23, you can however do: SELECT * FROM table_name ORDER BY RAND() This is useful to get a random sample of a set
My host run 3.22.27 and I don't think they will upgrade... is there another way?
June 25th, 2000, 11:59 PM
This slightly more complicated method works in earlier versions of MySQL:
"SELECT id,field1,field2,field,etc,id*0+RAND() as random_record FROM mytable ORDER BY random_record"
"SELECT id,field1,field2,field,etc,id*0+RAND() as random_record FROM mytable ORDER BY random_record LIMIT 10"
LIMIT 10 (or whatever number you want) limits the number of random results returned by any one query)
June 26th, 2000, 04:24 AM
It works great, thanks!