表1
+----+------------------------+------+
| id | title | year |
+----+------------------------+------+
| 1 | Carmencita | 1894 |
| 2 | Le clown et ses chiens | 1892 |
| 3 | Pauvre Pierrot | 1892 |
+----+------------------------+------+
表2:
+----+------------------------+------+
| id | title | year |
+----+------------------------+------+
| 1 | Carmencita | 0 |
| 2 | Le clown et ses chiens | 0 |
| 3 | Pauvre Pierrot | 0 |
+----+------------------------+------+
如何将年份列从表1复制到表2,以便它们具有正确的ID
答案 0 :(得分:3)
这将更新Table2中的年列,以匹配Table1中的值,其中 id 在两个表中都相同:
update Table2
inner join Table1 on Table1.`id` = Table2.`id`
set Table2.`year` = table1.`year`;