Advertisement
valchak

Posts and Commentators

Oct 18th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.21 KB | None | 0 0
  1. # 14. Posts and Commentators
  2. SELECT
  3.     p.id,
  4.     p.caption,
  5.     COUNT(DISTINCT c.user_id) AS `users`
  6. FROM posts As p
  7. LEFT JOIN comments AS c
  8.     ON p.id = c.post_id
  9. GROUP BY p.id
  10. ORDER BY `users` DESC, p.id;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement