Getting the SUM() of claps and at the same time counting bookmarks in one query

You need to aggregate before doing the joins. One method is: SELECT p.*, u.name, u.avatar, b.bookmarksCount, c.totalClaps FROM posts p LEFT JOIN users u ON u.id = p.owner LEFT JOIN (SELECT b.post_id, COUNT(*) as bookmarksCount FROM bookmarks b GROUP BY b.post_id ) b ON b.post_id = p.id LEFT JOIN (SELECT c.post_id, SUM(claps_count) as totalClaps FROM … Read more