【发布时间】:2022-01-24 01:29:54
【问题描述】:
MySQL:如何将两个表合并在一起,相同的行数对应相同的 ID 号?有人可以帮我写一个查询。我是这样写的:
INSERT INTO table1.code
SELECT code FROM table2
WHERE table1.id = table2.id
但是,我收到 mysql 错误:#1054 - Unknown column 'table1.id' in 'where clause'
表 1
| id | name | code |
|---|---|---|
| 1 | abc | |
| 2 | def | |
| 3 | ghi |
表 2
| id | code |
|---|---|
| 1 | 12 |
| 2 | Ab |
| 3 | D2 |
必需的 MYSQL 数据库表 1
| id | name | code |
|---|---|---|
| 1 | abc | 12 |
| 2 | def | Ab |
| 3 | ghi | D2 |
【问题讨论】: