如何将数据从一个表复制到另一个表?

时间:2016-05-12 09:50:13

标签: mysql sql database

我有2个表,国家和分区与ff架构:

country               division
-----------           ------------
countrycode           divisioncode
contryname           countrycode
                      divisionname

我想将国家/地区表中的数据复制到分区表中,其中国家代码分为分区代码,分区表中的国家代码和分区名称的国家/地区名称

对于前者,美国 - 美国进入美国,美国,美国的分区表。

2 个答案:

答案 0 :(得分:3)

使用 INSERT INTO ... SELECT

<强>查询

INSERT INTO division(divisioncode, countrycode, divisionname)
SELECT countrycode, countrycode, countryname
FROM country;

答案 1 :(得分:3)

insert into division (divisioncode, countrycode, divisionname)
select t1.countrycode, t1.countrycode, t1.countryname
from country t1

请参阅:http://dev.mysql.com/doc/refman/5.7/en/insert-select.html