2

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?

Paul White
95.3k30 gold badges439 silver badges689 bronze badges
asked Feb 27, 2021 at 17:58

1 Answer 1

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 
answered Feb 27, 2021 at 18:15
1
  • Hello, thank's thank's thank's thank's it works prefectly Commented Feb 28, 2021 at 14:10

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.