简体   繁体   中英

How do I restore only 1 mySQL value row for an entire table?

I have a serious issue with a mySQL database, but luckily I have backups. I just don't know how to restore that affected part without modifying the others.

I have rows with:

product | name | country

The product and name should stay as they are, but for each of the rows I have to restore the country part as they are in the .sql backup file. What's the easiest way to do that?

Something like

`UPDATE my_table SET country="123,123,134" WHERE product="9876"
`UPDATE my_table SET country="482,482,593" WHERE product="4543"

etc.

The country value is different for each product .

Thanks so much for any help!

I assume there is a primary key in your table that you just did not mention, so it is actually:

my_table
ID | product | name | country

Restore the table from your backup under another name, let's say my_backup_table . Then use the following SQL:

UPDATE my_table SET my_table.country = my_backup_table.country 
WHERE my_table.ID = my_backup_table.ID

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM