I have the following tables set up:
Articles:
ID | TITLE | CONTENT | USER | NUM_COMMENTS
COMMENTS
ID | ARTICLE_ID | TEXT
I need a sql statement which updates the NUM_Comments field of the articles table with teh count of the comments made against the article like:
update articles a, comments f
set a.num_comments = COUNT(f.`id`)
where f.article_id = a.id
The sql above doesn't work and I get an Invalid Use fo Group function error. I'm using MySQL Here.