I have following three tables in mysql.
postid | post_content => posts
commentid | post | comment_content => comments
commentvoteid | comment | voter => comment_votes
I want to fetch all the comments, counting its votes for a post.
commentid | comment_content | comment_votes => my_result
I have tried the following query but not getting the desired result.
SELECT commentid,comment_content,count_comments.total AS comment_votes
FROM comments
INNER JOIN(SELECT COUNT(*) AS total FROM comment_votes WHERE comment=comments.commentid) AS count_comments
WHERE post={$postId}
Is it possible to fetch the result as I wanted? How can I do that?