Re: Difficult count statement. Need some sql advice

From: Date: Sat, 02 Mar 2002 21:01:02 +0000
Subject: Re: Difficult count statement. Need some sql advice
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-17417@lists.php.net to get a copy of this message
Well off the top I'd say your forgot the join condition between the fo_topics and the fo_forums tables. Right now you're counting the Cartesian product of the two tables. Also you can't select an aggregate function (like count) and regular columns without a group by on the same columns. F on 3/2/02 8:37 AM, php-db-digest-help@lists.php.net at php-db-digest-help@lists.php.net wrote: > From: "Andy" <news.letters@gmx.de> > Reply-To: "Andy" <news.letters@gmx.de> > Date: Sat, 2 Mar 2002 17:36:41 +0100 > To: php-db@lists.php.net > Subject: Difficult count statement. Need some sql advice > > 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 > >

« previous php.db (#17417) next »