Re: Super SQL problem! Please advise!

From: Date: Thu, 08 Feb 2001 17:57:35 +0000
Subject: Re: Super SQL problem! Please advise!
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-38789@lists.php.net to get a copy of this message
"Sandeep Hundal" <sandeep_wde@yahoo.com> wrote: > thanks for the tip steve. i read up on left joins, and got this: > SELECT diary.id, diary.thedate, diary.topic, diary.entry > FROM diary > LEFT JOIN comments > ON diary.id = comments.id; > > but it only joins the two tables. Right. It took care of your main problem though. > What I need is only 1 column from > the second table, counted. Something like this, but that doesn't work > :( > SELECT diary.id, diary.thedate, diary.topic, diary.entry > FROM diary > LEFT JOIN comments.id > ON diary.id = comments.id > COUNT(comments.id) > GROUP BY comments.id; The order of your statement is a little off. Try this: SELECT diary.id, diary.thedate, diary.topic, diary.entry, COUNT(comments.id) FROM diary LEFT JOIN comments.id ON diary.id = comments.id GROUP BY comments.id; If that doesn't work you might want to look at running two queries and saving their results as temporary tables and then running a query to join the two temporary tables to get what you want. Also, for SQL questions like this you'll get better [or more or quicker] responses on the mysql mailing list. Sign up at www.mysql.com. -- Steve Werby COO 24-7 Computer Services, LLC Tel: 804.817.2470 http://www.247computing.com/

« previous php.general (#38789) next »