How to fix the amount of comments displayed for each post?

I nailed it:

UPDATE wp_posts as p SET comment_count =(SELECT count(*) FROM `wp_comments` WHERE `comment_post_ID`=p.ID);

error code: 523