I have the following problem:
- there's one table with news,
- and a second table with comments (related to the news table by 'news_id' column)
Now, I would like to know, whether there's some possibility to get a list of news with a number of comments for each, just through one query?
I've tried this:
Code: Select all
SELECT *, COUNT(*) as comments_c
FROM news, comments
WHERE comments.object_id = news.id
GROUP BY news.id
ORDER BY news.time DESC
LIMIT 0, 5So, is there some other way how to do this just in one query or do I have to go through every row of the result and do a query for each?
Thanks