Such as: posts post table
Create TABLE posts (
POSTS_ID,
ForumID, (forum ID)
Posts_title,
Posts_posttime,
)
Comments Comment Form
CREATE TABLE Comments (
COMMENTS_ID,
Postsid,
Comments_content,
Comments_posttime,
)
The result I want is: Read all posts with Forum ID 1 and count the total number of comments for each post.
I use COUNT (comments_id) as commentsnum to comment, but the post is not commented on the comment form, group by ignores
posts_id ForumID Commentsnum
1 1 4
2 1 5
3 1 4
4 1 0
I want to be a post in the comment table when no comments, return 0, or return null also OK, how to get
Reply to discussion (solution)
Select A.posts_id,a.forumid,count (b.comments_id) as Commentsnum from posts a left joins comments B on A.posts_id=b.pos Tsidgroup by B.postsid has a.forumid=1
Resolved, Xie Moderator, have thought of having but not to use = =