1

I have a table srSignals, in a database called signals that looks like so:

animal      inserttime              id
dog         1970-00-00 00:00:00     3042
cat         1970-00-00 00:00:00     3041
monkey      1970-00-00 00:00:00     3040
hamster     1970-00-00 00:00:00     6

All of my inserttime values got reset to 1970 on accident. Luckily I have a backup of the database signals with the correct inserttime values (and corresponding id values). The backup file is called signals.sql.gz (with signals.sql inside the gz compression, obviously).

My question is this: using phpMyAdmin, how can I update the column inserttime where the id of the existing table = the id of the backup file. Note that I do NOT want to completely restore the table as other stuff has been added to the database in the interim.

I'm not sure the best way to get about this - restore functionality of phpMyAdmin? Some fancy update / load?

Thanks!

1 Answer 1

7

Restore the backup to a different database and then do an update:

UPDATE database1.table, database2.table
SET database1.table.field = database2.table.field
WHERE database1.table.idfield = database2.table.idfield
3
  • Jim's answer is better (though it doesn't have to be a different database, just a different table name). Sep 18, 2012 at 21:39
  • getting error '#1054 column database2.table.idfield does not exist in where clause' though I can assure you the column does exist. Do I need to use a join statement here to make this work? Sep 18, 2012 at 22:04
  • 4
    I ended up going with this solution though a slightly different way: I extracted just the backup table I needed from the .sql file, created a new table and imported the backup table (same database), and then ran an UPDATE command to solve my problem: UPDATE table1 INNER JOIN table2 ON table1.id = table2 .id SET table1.inserttime = table2 .inserttime Sep 18, 2012 at 22:19

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.