MYSQL UPDATE with IN and Subquery

前端 未结 5 1102
余生分开走
余生分开走 2020-12-30 09:18

Hi i have tables like this :

table entry :

id | total_comments
_____________________
1 | 0
2 | 0
3 | 0
4 | 0

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-30 10:19

    Try:

    UPDATE entry
      SET total_comments = (SELECT COUNT(*) 
                            FROM comments
                            WHERE entry.id = comments.eid
                            GROUP BY id)
    

提交回复
热议问题