Re: MySQL: Random select with specific count of a column
| From: | franciccio | Date: | Wed, 30 Jun 2004 23:30:01 +0000 |
| Subject: | Re: MySQL: Random select with specific count of a column | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-35064@lists.php.net to get a copy of this message | ||
I suggest to first analize the problem and then go through the query, php
coding ...etc etc
In the table u have only one superkey which is also a key and it is made of
the three fields (attributes) 'category', 'language' and ' name'. You
should
consider to look for a prymary key randomly, toghether with some restriction
in the search. Something like select the pryimary key from the table where
'category' equals a number(1, 2,3,....n) and 'name' equals some random
criterium generated number. A random criteria could be generating a random
variables between the ascii code representing the alphabet letters (from 97
to 122 to cover a,b,c,...z).
You need to do some work before u can get an executable code here.
Hope can open a road
Bye
"Torsten Roehr" <roehr@zilleon.com> ha scritto nel messaggio
news:20040629110054.63882.qmail@pb1.pair.com...
> Hi,
>
> I've got the following table:
>
> category language name
> 1 de a
> 1 de b
> 1 de c
> 2 de a
> 2 de b
> 2 de c
> 3 de a
> 3 de b
> 3 de c
> ...
> 1 en a
> 1 en b
> 1 en c
>
> I would like to select 6 random rows where the language is 'de' AND make
> sure that I will always have 2 rows of EACH category in my result set:
> 1 de b
> 1 de c
> 2 de a
> 2 de c
> 3 de a
> 3 de b
>
> Any help greatly appreciated.
>
>
> Thanks and best regards,
>
> Torsten Roehr