[eluser]überfuzz[/eluser]
This isn't really a CI problem, but I try anyway.
I'm having two tables in a simple blogg I'm building. Right now I wanna fetch all headlines and count every comment made, to each headline.
Headline 1
comments 4
Headline 2
comments 1
Headline 2
comments 0 - This is where I mess up.
etc
I get gnarly when there's no comment made. This is my current sql:
Code:
SELECT
blogg.ID AS ID,
count('blogg_ID') AS comments,
blogg.headline AS headline
FROM
blogg
LEFT JOIN
comments ON blogg.ID = comments.blogg_ID
WHERE
activ = 1
GROUP BY
ID
My problem is that depending on how I JOIN the tables I get a row if there is a match and if there's no match, no comment, I don't get that specific row. Right now I can't come up with an idea to a solution. Help would be appreciated!