Re: MySQL: Random select with specific count of a column

From: Date: Wed, 30 Jun 2004 10:50:45 +0000
Subject: Re: MySQL: Random select with specific count of a column
References: 1 2  Groups: php.db 
Request: Send a blank email to php-db+get-35047@lists.php.net to get a copy of this message
"Rui Cunha" <rui.cunha@ual.pt> wrote in message news:20040630091042.AFC6D156CE@odin.ual.pt... > Hi Torsten, > > until now,the best i could get was getting 6 random rows...still working on > ensuring to retrive just 2 rows for category...meanwhile,you can solve the > problem easily with a php loop trough the following query: > > select field_id , language , category > from yourtable > where language = 'de' > group by category , field_id > order by category , rand() > limit 6; > > PS1: i'm considering you're using just one table and my table structure is > as follows: yourtable (field_id , language, category). > in case you're using more than 1 table, just add the required joins... > > hope this helps. Hi Rui, thank you very much for your efforts. I guess I have to do seperate queries (as you suggested) for each category and then join the results. Thanks again and best regards, Torsten

« previous php.db (#35047) next »