MySQL Forums
Forum List  »  MySQL Workbench

New query for dataset
Posted by: Umar Abdur Rehman
Date: July 31, 2015 11:21AM

Hi,

I am writing a query in mySQL. I have 2 tables posts and comments. Tables have the following columns;

1. Posts(post_id, post_title, post_author, post_author_id, post_comments, post_content)
2. Comments(comment_id, comment_post_id, comment_body, comment_author)

One blogger can post thousands of posts and for each post there can be hundreds of comments. I have written a query to count the unique commenters for a post of blogger Which is given below;

SELECT post_id, post_author, post_comments, COUNT(DISTINCT comment_author) FROM engadget.posts a join engadget.comments b ON a.post_id=b.comment_post_id WHERE post_author_id=4;

Instead of writing a query for each post of a blogger, Is there anyway to write one query that displays a table with that has all the posts of a blogger and has 3 columns, one shows the post_id, 2nd shows the post_comments and the third shows the unique commenters for that post?

Options: ReplyQuote


Subject
Views
Written By
Posted
New query for dataset
1080
July 31, 2015 11:21AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.