Re: Got a challenge for ya guys
| From: | Anuradha Ratnaweera | Date: | Tue, 26 Dec 2000 13:23:10 +0000 |
| Subject: | Re: Got a challenge for ya guys | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-5437@lists.php.net to get a copy of this message | ||
On Mon, 25 Dec 2000, Noah Spitzer-Williams wrote:
> aight i got these two tables: lets structure them like this:
>
> TABLE1
>
> username | group | sex
> john | 1 | M
> mike | 1 | M
> jen | 2 | F
>
> TABLE2
>
> username | age
> john | 2
> mike | 3
> jen | 2
>
Just a minor point first. I am not sure how to create a field group? Isn't
it a keyword?
> here what i want to do: find how many unique groups are of age '2'?
>
> its quite easy to find how many different people are of age '2' but
> how can i get the number of groups?
select distinct t1.group
from table1 t1, table2 t2
where t1.username = t2.username
and t2.age = 2;
> also, i dont want to list the same group more than once. i'd like to
> have this all done in mysql so i can calculate how many results (see a
> search engine comin here...hehe)
Sometimes, you may have to use sub select queries if you want to develope
more advanced queries along these lines, but as far as I know mysql
doesn't support them. I use postgresql because of this reason. However,
you can obtain the same results on mysql using multiple tables and
queries.
Anuradha