Re: Super SQL problem! Please advise!
| From: | Sandeep Hundal | Date: | Sat, 10 Feb 2001 01:59:38 +0000 |
| Subject: | Re: Super SQL problem! Please advise! | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-39046@lists.php.net to get a copy of this message | ||
Thanks a lot for your help everyone!!! It worked!! Woohoo!! Not only
that, I learned about joins! :)
/sunny
--- Steve Werby <steve@247computing.com> wrote: > "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/
__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35
a year! http://personal.mail.yahoo.com/