0

我有两个表(MySQL):

论坛:match_static_id,评论,...

匹配:static_id,…………

sql语句:

SELECT  forum.match_static_id, count(forum.comments) 'comments_no', matches.* 
from forum 
INNER JOIN matches ON forum.match_static_id = matches.static_id   
group by forum.match_static_id

即使我使用 group by,我也没有为每个匹配获得正确数量的评论(它总是乘以评论示例的数量 4 评论它返回 8)。我的 sql 错了吗?我只是想从你那里得到线索吗?

4

1 回答 1

-1

You should use Left join insted of inner

SELECT forum.match_static_id, count(forum.comments) 'comments_no', matches.* from matches LEFT JOIN forum ON forum.match_static_id = matches.static_id
group by forum.match_static_id

于 2013-07-09T14:04:00.443 回答