mysql update query with sub query

前端 未结 3 1388
臣服心动
臣服心动 2020-11-30 23:46

Can anyone see what is wrong with the below query?

When I run it I get:

#1064 - You have an error in your SQL syntax; check the manual that co

3条回答
  •  旧巷少年郎
    2020-12-01 00:39

    For the impatient:

    UPDATE target AS t
    INNER JOIN (
      SELECT s.id, COUNT(*) AS count
      FROM source_grouped AS s
      -- WHERE s.custom_condition IS (true)
      GROUP BY s.id
    ) AS aggregate ON aggregate.id = t.id
    SET t.count = aggregate.count
    

    That's @mellamokb's answer, as above, reduced to the max.

提交回复
热议问题