Mysql 使用ID匹配的另一个表中的数据更新表

Mysql 使用ID匹配的另一个表中的数据更新表,mysql,sql,Mysql,Sql,所以我有这两张桌子 table1 +----+---------+ | id | type_id | +----+---------+ | 1 | 1 | +----+---------+ | 2 | 12 | +----+---------+ table2 +----+-----------+---------+ | id | table1_id | type_id | +----+-----------+---------+ | 5 | 1 |

所以我有这两张桌子

table1
+----+---------+
| id | type_id |
+----+---------+
|  1 |       1 |
+----+---------+
|  2 |      12 |
+----+---------+

table2
+----+-----------+---------+
| id | table1_id | type_id |
+----+-----------+---------+
|  5 |         1 |       0 |
+----+-----------+---------+
|  6 |         2 |       0 |
+----+-----------+---------+
我想使用table1中的id作为参考点,使用table1.type_id中的值更新table2.type_id

我不知道该怎么做

UPDATE table2
SET type_id = a.type_id
FROM table2 b
    JOIN table1 a ON a.id = b.table_id
此语句将正确利用
表2中的数据和
连接
以从
表A
中获取值

UPDATE T2
 SET table1_id = T1.type_id
FROM table2 AS T2
JOIN table1 AS T1
  ON T1.id = T2.table1_id
此语句将正确利用
表2中的数据和
连接
以从
表A
中获取值

UPDATE T2
 SET table1_id = T1.type_id
FROM table2 AS T2
JOIN table1 AS T1
  ON T1.id = T2.table1_id