Forum Moderators: coopster & phranque

Message Too Old, No Replies

order by RAND () AND group by ...

mysql select statments

         

benihana

12:54 pm on Feb 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



i have a simple mysql database with 5 different types of products.
I would like to be able to to select at random one of each type of product.
I have tried using:

"select * from table_name order by RAND() group by type"

but just get an error.

i realise i could write 5 select statemnents, but was wondering if there is a *better* way?

thanks

Damian

2:34 pm on Feb 17, 2003 (gmt 0)

10+ Year Member



I think it's in the order of your statement..try this:

"select * from table_name group by type order by RAND()"

benihana

3:31 pm on Feb 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thought id tried that but obviously not.
fixed now.
thanks