Mam problem z jednym zapytaniem.
Chcę pobierać z bazy informacje o artykułach i przy tym o ilości komentarzy i ocenie.
Gdy wyciągam tylko ilość komentarzy jest ok:
SELECT articles.id AS id, articles.title As title, users.username AS username, articles.pubish AS pubished, categories.name AS category, count( comments.text ) AS comments
FROM articles
JOIN users ON articles.author = users.id
LEFT JOIN categories ON articles.cat = categories.id
LEFT JOIN comments ON articles.id = comments.item_id
GROUP BY articles.id
i dane baza wypluwa takie jakie mają być czyli:

ale jak dodam jeszcze zapytanie o ocene (w tabeli z ocenami są kolumny id, item_id oraz rate przy czym rate to albo 1 albo -1). Zapytanie wygląda tak ale już jego wynik jest bardzo dziwny bo ani ilość komentarzy się nie zgadza ani ocena:
SELECT articles.id AS id, articles.title As title, users.username AS username, articles.pubish AS pubished, categories.name AS category, count( comments.id ) AS comments, sum( rank.rank ) AS rank
FROM articles
JOIN users ON articles.author = users.id
LEFT JOIN categories ON articles.cat = categories.id
LEFT JOIN comments ON articles.id = comments.item_id
LEFT JOIN rank ON articles.id = rank.item_id
GROUP BY articles.id

jak nie pytam o komentarze a tylko o ocene tez jest ok.
Proszę o pomoc w rozwiązaniu tego problemu bo już nie wiem jak to ugryźć.