我需要在两个表之间对MySql执行追加,我的第一个table1获取所有数据,但是对于table2,我只有EMAIL:
table1 (ID; FIRSTNAME; LASTNAME; EMAIL; BIRTH; CP)100 000行 table2 (ID; FIRSTNAME; LASTNAME; EMAIL; BIRTH; CP)1 000行
为例
表1:
1; JOHN; DOE; john.doe@gmail.com; 1981-06-06 00:00:00; 92220
表2:
NULL; NULL; NULL; john.doe@gmail.com; NULL; NULL
和
我想在table2上更新所有匹配的列:
1; JOHN; DOE; john.doe@gmail.com; 1981-06-06 00:00:00; 92220
答案 0 :(得分:1)
使用多表UPDATE
语法连接EMAIL
上的表并正确设置字段:
UPDATE table2 JOIN table1 USING (EMAIL) SET
table2.ID = table1.ID,
table2.FIRSTNAME = table1.FIRSTNAME,
table2.LASTNAME = table1.LASTNAME,
table2.BIRTH = table1.BIRTH
table2.CP = table1.CP