MySQL将数据从一个表复制到另一个表中的不同字段[重复]

时间:2022-09-15 22:41:01

This question already has an answer here:

这个问题在这里已有答案:

user table: id | facebookid | externalid | more data...

用户表:id | facebookid | externalid |更多数据......

userexternalid table: id | userid | facebookid | externalid

userexternalid表:id | userid | facebookid |外部ID

What I need is to write a query that gets all data from the user table and inserts is as following for every single row.

我需要的是编写一个查询来获取用户表中的所有数据,并为每一行插入如下内容。

userexternalid.userid = user.id
userexternalid.facebookid = user.facebookid 
userexternalid.externalid = user.externalid 

Can't seem to find anything like it on the web. Anyone an idea? Thanks

似乎无法在网上找到类似的东西。有人有想法吗?谢谢

1 个解决方案

#1


INSERT INTO userexternalid (userid, facebookid, externalid) 
    SELECT id AS userid, facebookid, externalid FROM user;

#1


INSERT INTO userexternalid (userid, facebookid, externalid) 
    SELECT id AS userid, facebookid, externalid FROM user;