Skip to content

Instantly share code, notes, and snippets.

@silentsudo
Created December 1, 2021 04:57
Show Gist options
  • Save silentsudo/8126b03ea254a549a21eb2eef198c485 to your computer and use it in GitHub Desktop.
Save silentsudo/8126b03ea254a549a21eb2eef198c485 to your computer and use it in GitHub Desktop.
SELECT f.id as feed_id, u.name, u.email,
(select count(*) FROM jpatest.likes where feed_id = f.id) as likes_count,
(select count(*) FROM jpatest.comments where feed_id = f.id) as comments_count
FROM feeds f
LEFT JOIN users u
ON f.user_id = u.id
WHERE u.id = 12055;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment