[eluser]winterain[/eluser]
This is actually a very common set up but it's the first time I'm coding this myself so obviously I've ran into a limitation of my SQL knowledge.
I'm making a blog kinda site with posts and comments, this is for the main post listing which lists posts from table "blog_posts" . Another table "blog_comments" are linked to the "blog_posts" table via the blog_posts.ID .
I'm trying to list the number of comments the post has IN THE MAIN POST LISTING page, I figured I should perform a join and count with the 2 tables.
However, Blog posts that do not have comments do not show up in this query. Can anyone help please? I'm not even sure if this should be the way to do it, or perhaps I'm over complicating things.
My current query is:
SELECT *, COUNT(*) AS count FROM blog_posts JOIN blog_comments ON blog_posts.ID = blog_comments.blog_id GROUP BY blog_id;
I realize that it is mainly because of the GROUP BY clause that causes posts that have no matching IDs to be excluded from the goup, but that only makes me more clueless on how to solve this.
Thanks for your time and help!