I have three tables in my database
1.Users (id,username)
2.Stories (id,user_id,content) here user_id is forigen key refers Users table id
3.Comments (id,user_id,story_id,comment) here user_id is forigen key refers Users table id and story_id is forigen key refers Stories table id
I need to get list of stories from Stories table with total number of comments on that post and username of the storie author
Here is my query for that
SELECT stories.id,stories.content,COUNT(stories.id) as totalcomment
FROM stories
JOIN comments
ON stories.id=comments.story_id GROUP BY stories.id
I will get the total comment of the each post ,but can't fetch the username of the storie author (ie username from Users table)
Userstable?