I have got table post
: int post_id, varchar title, text content
And table comment
:int comment_id, int post_id, varchar content
where post_id is a foreign key references table post.
How do i get the post_id and sum of comments of each post order by comments count. Thank you.
If you want posts that have no comments:
(This query uses the MySQLs GROUP BY with hidden columns extension).
If you don't want posts that have no comments you can use a simpler query: