0
       table 1                                     table 2

+---------+------------+                    +---------+------------+
| post_id | meta_value |                    |    ID   | post_title |
+---------|------------+                    +---------|------------+
|    1    |   value_a  |                    |    1    | title_abc  |
+---------|------------+                    +---------|------------+
|    2    |   value_b  |                    |    2    | title_xyh  |
+---------|------------+                    +---------|------------+
|    3    |   value_c  |                    |    3    | title_jer  |
+---------|------------+                    +---------|------------+
| .....   | .........  |                    |   ..... |   .......  |
+---------|------------+                    +---------|------------+
|   999   | value_xyzw |                    |   999   | title_bhw  |
+---------|------------+                    +---------|------------+

I have 2 tables. I try to replace the records from post_title (table 2) with meta_value {table 1).

Example:

value_a replace title_abc

value_b replace title_xyh

value_c replace title_jer

............

etc

Thank you!

2 Answers 2

1

You want an update with a join:

update table1 t1 join
       table2 t2
       on t1.post_id = t2.id
    set t1.meta_value = t2.post_title;
Sign up to request clarification or add additional context in comments.

2 Comments

i try to add another condition: meta_key = custom_title. meta_key is another column in table1
Ok. I got it: and t2.meta_key like 'custom_title'
1
UPDATE table1, table2 SET table1.metavalue = table2.post_title 
WHERE table1.id = table2.id

Comments

Your Answer

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.