0

I'd like to copy a number of rows from one table to another within phpmyadmin. The table i'm copying from is the profile table. The table user i'm copying to already exists but the columns do not. I'm attempting the following command in the SQL tab of phpmyadmin.

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

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

For some reason this isn't working out for me. I'm getting an error:

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

profileImage exists in the profile table, i.e. it is the name of one of my fields

Does anyone know what the problem might be?

15
  • Have you tried prefixing your table with your database name? INSERT INTO db.tbl and SELECT FROM db2.tbl ? Commented Aug 16, 2012 at 14:22
  • 3
    proileImage is misspelled, could that be the cause? Commented Aug 16, 2012 at 14:22
  • Yes i have, also with no success. Commented Aug 16, 2012 at 14:22
  • @RickKuipers Apologies, that was mistyped by me - that's not the problem, edited now Commented Aug 16, 2012 at 14:24
  • I think you answered the question yourself: the table exists, but the columns do not. Add the columns manually and run the query again. Commented Aug 16, 2012 at 14:25

2 Answers 2

1

If the error is #1054 - Unknown column 'proileImage' in 'field list' then, simply, that column doesn't exist in either (or both) your profile or your user table.

Just run the select part of the query, ie. SELECT profileImage, skypeName, facebookProfile, twitterProfile, reputation, genderPreference, agePreference, fluentLanguage, desiredLanguage FROM profile

Does that work?

If so, are you sure profileImage exists in the user table?

Sign up to request clarification or add additional context in comments.

4 Comments

When running your query i get MySQL returned an empty result set (i.e. zero rows). ( Query took 0.0003 sec ). profileImage does not exist in the user table, i thought my SQL query would create the those columns when copying them from the profile table?
Ah no, not at all. You'll have to create those columns first.
Oh right, perhaps i was expecting too much from MySQL! So if i had 100 columns in table X that i wanted to copy to table Y, i'd have to create all those columns in table Y before i could copy the data from those columns in table X?
Yes. I don't think you can do so programmatically in MySQL itself (but it's perhaps worth a new question), but you could certainly do so with php.
0

You can copy the structure of the table 1 to table 2 in phpmyadmin and can then run query to copy certain rows from table 1 to table 2.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.