Import CSV to Update rows in table

后端 未结 3 899
既然无缘
既然无缘 2020-12-05 07:40

There are approximately 26K products (posts) and each product has meta values like this:

\"enter

3条回答
  •  长情又很酷
    2020-12-05 08:12

    You can import the new data into another table (table2). Then update your primary table (table1) using a update with a sub-select:

    UPDATE table1 t1 set 
      sale_price = (select meta_value from table2 t2 where t2.post_id = t1.product_id)
    WHERE
      (select count(*) from table2 t2 where t1.product_id = t2.post_id) > 0
    

    This is obviously a simplification and you will most likely need to constrain your query a little further.

    Make sure to backup your full database before attempting. I recommend you work on a non-production database until the process works flawlessly.

提交回复
热议问题