MySQL: Count records from one table and then update another

Use a subquery:

UPDATE nations 
   SET count = (
       SELECT COUNT(id) 
         FROM poets 
        WHERE poets.nation = nations.id 
        GROUP BY id
       );

Leave a Comment