In mysql i have 2 table.


  • wp_postmeta_import


  • wp_postmeta_temp

These tables have these columns:

  • meta_id
  • post_id
  • meta_key
  • meta_value

I need to update only my column meta_value of wp_postmeta_temp when post_id is egual to post id of wp_postmeta_import and the value of meta_key is _variation_description because in table are other post_id with other value

i try some code an this is the only that work a little bit but it is change the row that i need and in the other meta_key it gives me NULL.

UPDATE wp_postmeta_temp  
SET meta_value = (
                      wp_postmeta_import.post_id = wp_postmeta_temp.post_id 
                      wp_postmeta_temp.meta_key = '_variation_description' 

The table have rows, for any post_id for exemple:

  • meta_id: variable (82649,82650..)
  • post_id: 5065
  • meta_key: _variation_description or _regular_price or total_sales ecc..
  • meta_value: variable (15, 0, 200 ...)

i hope that i'm clear anyone can help me, please?

1 Answer 1


you should join the tables, so that all rows are joint together.

Before you start this use a select with the inner join to see if it fits.

UPDATE wp_postmeta_temp wpmt 
INNER JOIN wp_postmeta_import wpi ON wpi.post_id=wpmt.post_id AND wpmt.meta_key = '_variation_description'
   SET wpmt.meta_value= wpi.meta_value 
  • Hello, thank's thank's thank's thank's it works prefectly Feb 28, 2021 at 14:10

Your Answer

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

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