"Sandeep Hundal" <[EMAIL PROTECTED]> 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/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to