根据同一表的不同列中存在的主键更新列

  • 本文关键字:存在 更新 mysql sql
  • 更新时间 :
  • 英文 :

>div class="s-table-container">
idtopic_idid
121null
2null1
UPDATE table t1
JOIN table t2 ON t1.id = t2.id2 -- join 2 tables copies according to the relation
SET t2.topic_id = t1.topic_id     -- copy the value into the column
WHERE t2.topic_id IS NULL;        -- update only rows without the value in the column

最新更新