Count and Group By ?
Posted: Tue Feb 17, 2009 10:29 am
I'm working on a blogging site and one of the customer requirements is to display the "Top 5 Bloggers". Meaning a list of the 5 most active users.
Following are the tables and as you would guess the BLOG table stores blog data and BLOG_COMMENT stores comments/replies to a blog.
Question: Is there a pure SQL approach to get a collective count of users from both tables?
I can achieve this with 2 queries then process the results with application code but would much rather do it with one SQL statement (if possible)
blog
--------
blog_id
title
content
user_id
blog_comment
-------------
blog_id
comment_id
content
user_id
Following are the tables and as you would guess the BLOG table stores blog data and BLOG_COMMENT stores comments/replies to a blog.
Question: Is there a pure SQL approach to get a collective count of users from both tables?
I can achieve this with 2 queries then process the results with application code but would much rather do it with one SQL statement (if possible)
blog
--------
blog_id
title
content
user_id
blog_comment
-------------
blog_id
comment_id
content
user_id