search

Home  >  Q&A  >  body text

MYSQL query to copy all data in a column from one database to another

I accidentally used the "Generate Description" feature on the Opencart SEO tool and it overwrote all of my product descriptions with the product title.

I have over 600 products and it would be a pain to remake them all.

I have a MYSQL backup that is 2 months old and contains most of the products except about 20 that were added later.

I have imported an old backup into a newly created database, what query can I run to copy and overwrite all the description column data from the backup table into the current table?

They are located at database.oc_product_description.description

Any help is greatly appreciated. This is driving me crazy

P粉005417748P粉005417748274 days ago574

reply all(1)I'll reply

  • P粉476475551

    P粉4764755512024-04-01 10:42:18

    If the two schemas are located in the same MySQL instance, please use the REPLACE INTO statement (backup before operation)

    means: restored database Database means: current database

    REPLACE INTO database.oc_product_description 
     SELECT * FROM old.oc_product_description

    This statement will replace the data with the primary key

    If you don't want to copy the entire table, do an update and copy the data from the old table to the database (product_id and language_id columns are primary keys)

    UPDATE database.oc_product_description AS pd1
     INNER JOIN old.oc_product_description AS pd2 ON pd2.product_id = pd1.product_id 
                                                 AND pd2.language_id = pd1.language_id
      SET pd1.description = pd2.description

    reply
    0
  • Cancelreply