I'm trying to write a query that will do the following:
I store articles in a table, and each article has a unique id (article_id). And then if some one responds to that article (a comment!) then, the unique id (article_id) is stored in a field called parent_id.
So for example, if I want to find out how many replies have been made to an article the query is as follows.
SELECT count(*) FROM article WHERE parent_id=article_id;
And that will give me a total of how many replies there have been.
The problem is this: I'm also trying to write a top 10 most active articles list, which involves finding out which articles have the most replies (and listing them descendingly)
I have a query but it doesn't seem to work. If anyone can suggest the correct query, I'd be most greatful!
Here's what I have so far:
SELECT *, COUNT(parent_id) AS c FROM article WHERE article_id = parent_id GROUP BY article_id ORDER BY c DESC LIMIT 0, 10
Regards, James.