RE: Left join does not work with Count() as expected

2009-02-19 Thread Martin Gainty
t; From: mat...@itlegion.ru > To: mysql@lists.mysql.com > Subject: Left join does not work with Count() as expected > > 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. >

Re: Left join does not work with Count() as expected

2009-02-19 Thread Peter Brawley
>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 Missing GROUP BY. PB - Artem Kuchin wrote: I have two simple tables. One - list of forums, second - list of messages and i want to get the list

Re: Left join does not work with Count() as expected

2009-02-19 Thread Olaf Stein
You need to group by forum_id... On 2/19/09 11:09 AM, "Artem Kuchin" 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 )

Left join does not work with Count() as expected

2009-02-19 Thread Artem Kuchin
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.so