$result = mysql_query("SELECT u.userid, u.username, u.level, u.karma, (u.mny + b.bank_mny) AS total_mny, u.mny, u.regsec, b.bank_mny, COUNT(t.username) AS topiccount, COUNT(m.username) AS posts
FROM mny_bank AS b
RIGHT JOIN users AS u ON u.username = b.bank_username
LEFT JOIN messages AS m ON u.username = m.username
LEFT JOIN topics AS t ON u.username = t.username
GROUP BY u.username
ORDER BY $order_by $order
LIMIT 0, 50") or die(mysql_error()); |
Whenever the query is run, topiccount and posts are always equal to topiccount times the posts. Could anyone here explain why and tell me how to avoid it?