Jump to content
WebFlake
  • 0

copy coloumn in MySQL from database to another db


teokrata

Question

Hi!

 

I have a new problem :)

 

I need to copy a coloumn from a database to another database.

 

For example.. I hava a database, named dbase1 and there is a profile_field_data table and it's have a thanked coloumn. I want copy this to another database: dbase2 - profile_field_data - thanked coloumn.

 

Anybody can help me about this sql command?

 

 

Thanks in advance!!

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Close but not quite. That way it overwrites all fields in the database.

 

If you are trying to copy just one field from one db to another you have to make sure the tables have equal number of rows and they matchexcept for not having the one field.

First create the thanked field in the second database using phpmyadmin.

 

Next run this sql command changing the database names to your databases. The profile_id may not exist but the real name should be the first column in the table...

 

UPDATE dbase2.profile_data set thanked = (select thanked from dbase1.profile_data where dbase2.profile_id = dbase1.profile_id )
Edited by Lock Down
  • Upvote 1
Link to comment
Share on other sites

  • 0

Open cPanel > phpMyAdmin > Click the table you want, then click export, then import it into db2 :)

Achievements:

February 14 2013 - Joined WebFlake & Became Moderator.
March 26 2013 - Became a Dad of 1 kid.
April 8 2015 - Became a Dad of 2 kids.
July 15 2015 - Retired as a Moderator.
November 11 2016 - Passed my Car Driving Licence.
April 13 2017 - Became apart of the Junior Moderator Team.

Link to comment
Share on other sites

  • 0

Thank you Lock! You are excellent! :)

 

I must changed the commands on the end, because you must say the database, where is the "profile_id", but everything other are perfect!

 

so the corrected command is this:

 

 

UPDATE dbase2.profile_data set thanked = (select thanked from dbase1.profile_data where dbase2.profile_data.profile_id = dbase1.profile_data.profile_id)

 

Thank you once more!!

Edited by teokrata
Link to comment
Share on other sites

  • 0
The question(s) in this support topic have been answered and the owner has been able to solve the problem. Because of this, the support topic has been closed and moved.If you have other questions, please open a new topic.

Achievements:

February 14 2013 - Joined WebFlake & Became Moderator.
March 26 2013 - Became a Dad of 1 kid.
April 8 2015 - Became a Dad of 2 kids.
July 15 2015 - Retired as a Moderator.
November 11 2016 - Passed my Car Driving Licence.
April 13 2017 - Became apart of the Junior Moderator Team.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...