MySql:将数据从一个table插入到另一个

MySql: Insert data from one table to another

Table A:
+----+-------+--------+-------+
| id | Tag   | Name   | Size  |
+----+-------+--------+-------+
|  1 | One   | Bob    | 14.29 |
|  2 | Two   | Charles| 28.56 |
|  3 | Three | Frank  | 76.95 |
+----+-------+--------+-------+
Table B:
+----+-------+--------+-------+
| id | Tag   | Name   | Size  |
+----+-------+--------+-------+
|  55| Two   | Charles|     0 |
|  68| Three | Frank  |     0 |
+----+-------+--------+-------+

我想要的:尺寸从TableA到TableB

最近查询:

  INSERT INTO B (Size) 
  SELECT Size FROM A 
  WHERE A.Tag = B.Tag 
  AND A.Name = B.Name;

导致错误: 错误 1054 (42S22):'where clause' 中的未知列 'B.Tag'。

I am newbie to MySql and guess this is a standard database task.


您需要更新 table B 而不是插入新行。
UPDATE 语句中使用连接:

UPDATE B
INNER JOIN A ON A.Tag = B.Tag AND A.Name = B.Name
SET B.Size = A.Size;