homepage Welcome to WebmasterWorld Guest from 54.161.246.212
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

    
Mysql how to move fields from one table to another
wheel

WebmasterWorld Senior Member wheel us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4370530 posted 11:45 am on Oct 4, 2011 (gmt 0)

I have a database that got hacked. Resulted in my deleting contents of field A in a database. Have a backup copy of the database from a week ago. If each record has a unique identifier say in field B, how can I do this:
From backup, select all field A.
Insert into live database, all field A's where field B=field B from backup.

TIA!

 

mark_roach

10+ Year Member



 
Msg#: 4370530 posted 12:28 pm on Oct 4, 2011 (gmt 0)

I think this will work but have not checked the syntax :

update tablea, tableb set tablea.cola=tableb.cola where tablea.colb=tableb.colb

mark_roach

10+ Year Member



 
Msg#: 4370530 posted 12:37 pm on Oct 4, 2011 (gmt 0)

Just realised you have the data in a seperate database. Never done this but I think the following should work :

update db1.table, db2.table set db1.table.cola=db2.table.cola where db1.table.colb=db2.table.colb

If ir doesn't just dump the table you need from the backup using mysldump and then import it into the original database using a different name and use the SQL in my first post.

wheel

WebmasterWorld Senior Member wheel us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4370530 posted 1:04 pm on Oct 4, 2011 (gmt 0)

Make backups first huh? :)

Thanks, I'll give it a whirl. Firstoption looks the most promising.

whoisgregg

WebmasterWorld Senior Member whoisgregg us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4370530 posted 8:32 pm on Oct 4, 2011 (gmt 0)

You're probably going to want to learn the "INSERT INTO ... SELECT" syntax:
http://dev.mysql.com/doc/refman/5.1/en/insert-select.html [dev.mysql.com]

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved