Hi,
also ich raste bald aus, ich krieg das einfach nicht hin! Ich hab hier mal ne kleine Grafik gebastelt, in der Hoffnung jemand kann mir die Lösung sagen - ich komm einfach nicht mehr weiter!
+----+-----------+----------+---------+-----------+ +--------------+
tbl_news | id | author_id | headline | content | timestamp | + | num_comments |
+----+-----------+----------+---------+-----------+ +--------------+
^ ^
| |
| +--------------+
| |
| username | count(parent_id)
| |
| |
+----+----------+ +-----------+
tbl_users | id | username | tbl_comments | parent_id |
+----+----------+ +-----------+
Wie schon gesagt, ich will die Anzahl der Kommentare (jeder hat eine parent_id, die zu einer News gehört) in num_comments stehen haben. Ein Query hätte ich da schon: Aber es liefert mir sehr seltsame Zahlen für num_comments - ich hab schon alles ausprobiert, aber ich schaffs einfach nicht :(
SELECT n.id, n.headline, n.content, n.author_id, n.timestamp, u.username, count(c.parent_id) AS num_comments
FROM al_news n, al_users u, al_news n2 LEFT JOIN al_comments c ON n2.id = c.parent_id
WHERE (n.author_id = u.id) GROUP BY c.parent_id