1

In mysql i have 2 table.

First

  • wp_postmeta_import

Second

  • 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 = (
                    SELECT 
                      meta_value 
                    FROM 
                      wp_postmeta_import 
                    WHERE 
                      wp_postmeta_import.post_id = wp_postmeta_temp.post_id 
                    AND 
                      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

0

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 
1
  • 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 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.