Welcome Guest, Not a member yet? Register   Sign In
Multiple joins and multiple counts
#2

[eluser]Daniel H[/eluser]
...now I'm using two subqueries to get the counts... not sure if that is good practice?!

Code:
SELECT posts.id, posts.title,

    (SELECT COUNT(c.id) AS c_count FROM posts AS p LEFT JOIN post_comment AS pc ON p.id = pc.post_id INNER JOIN comments AS c ON pc.comment_id = c.id WHERE p.id = posts.id) AS comment_count

FROM posts

ORDER BY posts.id DESC


Messages In This Thread
Multiple joins and multiple counts - by El Forum - 11-19-2008, 04:32 AM
Multiple joins and multiple counts - by El Forum - 11-19-2008, 05:28 AM
Multiple joins and multiple counts - by El Forum - 11-19-2008, 06:03 AM
Multiple joins and multiple counts - by El Forum - 11-19-2008, 06:04 AM



Theme © iAndrew 2016 - Forum software by © MyBB