Re: Difficult count statement. Need some sql advice
| From: | Bill Morrow | Date: | Sat, 02 Mar 2002 18:11:55 +0000 |
| Subject: | Re: Difficult count statement. Need some sql advice | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-17416@lists.php.net to get a copy of this message | ||
On Sat, Mar 02, 2002 at 05:36:41PM +0100, Andy wrote:
> Hi there,
>
> I would like to querry my db for following result
>
> - Count the number of topics listed in the table fo_topics,
> but only the topics where the belonging forum is not in the archive mode
> ( this is when table fo_forums field archive is 1)
>
> I tryed following querry but this is for sure wrong:
>
> SELECT COUNT(t.*) AS c, f.archive, f.forum_id
> FROM fo_topics t, fo_forums f
> WHERE f.archive != 1
>
> Can this be that difficult?
>
> Thanx for any help
>
> Andy
You need to join the two tables together:
select count(t.*) as c, f.archive, f.forum_id
from fo_topics t, fo_forums f
where t.forum_id = f.forum_id and f.archive != 1
might work. I assume you have a foreign key in fo_topics linking to fo_forums.
Bill