Skip to content

Instantly share code, notes, and snippets.

@silentsudo
Created December 1, 2021 04:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save silentsudo/efae82349ae885c6c25f2028340e6c46 to your computer and use it in GitHub Desktop.
Save silentsudo/efae82349ae885c6c25f2028340e6c46 to your computer and use it in GitHub Desktop.
SELECT f.id, u.email,
count(distinct l.id) as likes_count,
count(distinct c.id) as comments_count
FROM feeds f
INNER JOIN users u ON f.user_id = u.id
INNER JOIN likes l on l.feed_id = f.id
left join comments c on c.feed_id = f.id
WHERE u.id = 12055
group by f.id order by comments_count asc;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment