List:General Discussion« Previous MessageNext Message »
From:Olaf Stein Date:February 19 2009 4:48pm
Subject:Re: Left join does not work with Count() as expected
View as plain text  
You need to group by forum_id...


On 2/19/09 11:09 AM, "Artem Kuchin" <matrix@stripped> wrote:

> I have two simple tables. One - list of forums, second - list of
> messages and i want to
> get the list of forums with number of messages in each.
> 
> Here is the query:
> 
> SELECT forums.id , COUNT( forum_msg.id ) AS cnt
> FROM forums
> LEFT JOIN forum_msg ON forums.id = forum_msg.forum_id
> ORDER BY forums.sorder ASC
> 
> The problem is that if  a forum does not have any messages then the line
> with such forums.id does not appear at all.
> 
> If i delete COUNT( forum_msg.id ) AS cnt from Select  - i get all forums,
> as expected. If  i leave the count() as shown - i get only forums with
> messages
> in the result. As far as i can remember it was not like this before. I
> am running
> 5.1.3
> 
> --
> Artem Kuchin

----------------------------------------- Confidentiality Notice:
The following mail message, including any attachments, is for the
sole use of the intended recipient(s) and may contain confidential
and privileged information. The recipient is responsible to
maintain the confidentiality of this information and to use the
information only for authorized purposes. If you are not the
intended recipient (or authorized to receive information for the
intended recipient), you are hereby notified that any review, use,
disclosure, distribution, copying, printing, or action taken in
reliance on the contents of this e-mail is strictly prohibited. If
you have received this communication in error, please notify us
immediately by reply e-mail and destroy all copies of the original
message. Thank you.
Thread
Left join does not work with Count() as expectedArtem Kuchin19 Feb
  • Re: Left join does not work with Count() as expectedOlaf Stein19 Feb
    • InnoDB - CREATE INDEX - Locks table for too longClaudio Nanni19 Feb
      • Re: InnoDB - CREATE INDEX - Locks table for too longBaron Schwartz20 Feb
        • Re: InnoDB - CREATE INDEX - Locks table for too longClaudio Nanni21 Feb
        • Re: InnoDB - CREATE INDEX - Locks table for too longClaudio Nanni16 Mar
  • Re: Left join does not work with Count() as expectedPeter Brawley19 Feb
  • RE: Left join does not work with Count() as expectedMartin Gainty19 Feb