我有两张桌子(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
我没有为每个匹配得到正确数量的评论(它总是将评论数量乘以4回复8的评论)甚至我使用group by。我的sql错了,我只想要你的线索吗?
答案 0 :(得分:-1)
您应该使用左连接而不是内部
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