mysql 多次将数据库行从数据库 1 复制到新数据库 2,循环遍历数据库 3 的值

mysql copy database rows from database 1 multiple times to new database 2, looping through a value of database 3

我想使用 mysql 将值从 table 复制到另一个,同时循环第三个 table 以在第二个中设置特定值。

Table 1 称为国家,结构和数据:

countries
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ countries_id + countries_name + countries_iso_code_2 + countries_iso_code_3 +
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ 1            + Belgium        + BE                   + BEL                  +
+ 2            + Netherlands    + NL                   + NLD                  +
+ 3            + Germany        + DE                   + DEU                  +
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

行 countries_id 和 countries_name 需要复制到 table countries_name。对于来自 table 种语言的每种 language_id。 Table2

countries_name
+++++++++++++++++++++++++++++++++++++++++++++++
+ countries_id + language_id + countries_name +
+++++++++++++++++++++++++++++++++++++++++++++++
+ 1            + 1           + Belgium        +
+ 2            + 1           + Netherlands    +
+ 3            + 1           + Germany        +
+ 1            + 3           + Belgium        +
+ 2            + 3           + Netherlands    +
+ 3            + 3           + Germany        +
+ 1            + 4           + Belgium        +
+ 2            + 4           + Netherlands    +
+ 3            + 4           + Germany        +
+++++++++++++++++++++++++++++++++++++++++++++++

table 3

languages
+++++++++++++++++++++++++++++++++
+ languages_id + name    + code +
+++++++++++++++++++++++++++++++++
+ 1            + English + en   +
+ 3            + Dutch   + nl   +
+ 4            + German  + de   +
+++++++++++++++++++++++++++++++++

我知道如何对单次传递执行此操作,但不知道如何进行多次传递。

CREATE TABLE countries_name (

countries_id int(11) NOT NULL,

language_id int(11) NOT NULL DEFAULT 1,

countries_name varchar(64) NOT NULL,

UNIQUE countries (countries_id, language_id),

KEY idx_countries_name_zen (countries_name)

) ENGINE=MyISAM;

INSERT INTO countries_name (countries_id, countries_name)

SELECT c.countries_id, c.countries_name

FROM countries c;

http://sqlfiddle.com/#!9/bd3c7/1

如果我的目标正确:

INSERT INTO countries_name (countries_id, language_id, countries_name)
SELECT 
c.countries_id, 
l.languages_id,
c.countries_name
FROM countries c
LEFT JOIN languages l
ON 1;