将MySQL列从一个表复制到另一个表

问题描述:

我想在phpmyadmin中将一个表中的行数复制到另一个表中。我从中复制的表格是profile表格。表user我复制到已存在但列不。我正在尝试phpmyadmin的SQL选项卡中的以下命令。将MySQL列从一个表复制到另一个表

INSERT INTO user 
    (profileImage, 
    skypeName, 
    facebookProfile, 
    twitterProfile, 
    reputation, 
    genderPreference, 
    agePreference, 
    fluentLanguage, 
    desiredLanguage) 

(SELECT profileImage, skypeName, facebookProfile, twitterProfile, reputation, genderPreference, agePreference, fluentLanguage, desiredLanguage FROM profile) 

由于某种原因,这不适合我。我发现了一个错误:

#1054 - Unknown column 'profileImage' in 'field list'

profileImage存在于profile表,即是我的领域

有谁知道这个问题可能是什么的一个名字?

+0

你有没有试着用你的数据库名称前缀你的表? 'INSERT INTO db.tbl'和'SELECT FROM db2.tbl'? – Kermit 2012-08-16 14:22:39

+3

'proileImage'拼写错误,这可能是原因吗? – 2012-08-16 14:22:52

+0

是的,我也没有成功。 – garethdn 2012-08-16 14:22:59

如果错误是#1054 - Unknown column 'proileImage' in 'field list'那么,简单地说,该列存在两种(或两种),个人资料或用户表。

只需运行查询的选择部分,即。 SELECT profileImage, skypeName, facebookProfile, twitterProfile, reputation, genderPreference, agePreference, fluentLanguage, desiredLanguage FROM profile

运作的?

如果是的话,你肯定profileImage存在于用户的表?

+0

当运行查询,我得到'MySQL返回的查询结果为空(即零行) 。 (查询花了0.0003秒)'。 'user'表中不存在'profileImage',我认为我的SQL查询会在从'profile'表复制它们时创建这些列? – garethdn 2012-08-16 14:30:50

+0

啊不,完全没有。您必须先创建这些列。 – 2012-08-16 15:01:52

+0

哦,对,也许我期待MySQL太多!因此,如果我在表X中有100列要复制到表Y中,那么我必须在表Y中创建所有这些列,然后才能从表X中的这些列复制数据? – garethdn 2012-08-16 15:08:01

您可以在phpMyAdmin表1的结构复制到表2可以运行查询,以某些行从表1中复制到表2