Sql - Query Count For Related Table Affected By Other Join
The tables in this query are as follows: Post User Comment Tag Tagged_Post Post_Category I'm trying to query all relevant information about a post which has relations such as the
Solution 1:
The reason is that using multiple JOIN
s acts like a Cartesian product, so you get 2*3=6 rows for the group. When you apply count, you get 6 valid (non-null) values and that's your result.
To fix, use:
...COUNT(DISTINCT comment.comment_id) as comments
Post a Comment for "Sql - Query Count For Related Table Affected By Other Join"