Quantcast
Channel: MySQL Forums - MySQL Workbench
Viewing all articles
Browse latest Browse all 3724

New query for dataset (no replies)

$
0
0
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?

Viewing all articles
Browse latest Browse all 3724

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>