howachen@gmail.com wrote:
> hi,
>
>
> consider tables
>
> 1. blogs (id, num_article)
> 2. articles (id, blog_id)
>
> is it possible to perform the query in the following statement?
>
> update blogs, articles set blogs.num_article = count(*) where blogs.id
> = articles.blog_id group by articles.blog_id
>
> thanks.
This'll do it:
UPDATE blogs,
(
SELECT blog_id, count( * ) AS ac
FROM articles
GROUP BY blog_id
) AS t1
SET blogs.num_article = t1.ac WHERE blogs.id = t1.blog_id