MySQL Forums
Forum List  »  Newbie

MySQL copy fields based on conditions
Posted by: R. G.
Date: June 17, 2015 12:22PM

Not exactly sure how to describe this, I am copying text from table1 to table2. The destination of the copied text is based on two fields matching in table1 and table2.

The two fields that need to match are content_id with post_id and prop_name with meta_key

This is a one time thing with several (more than shown) prop_name/meta_key and content_id/post_id in 1000s of rows

BEFORE:
table1
+-------------+------------+------------+
| content_id  | prop_name  | content    |
+-------------+------------+------------+
| 15          | membersg   | mytext     |
| 15          | membersb   | mytext2    | 
| 15          | membersd   | mytext3    |
| 16          | membersg   | mytext4    |
| 16          | membersb   | mytext5    |
| 16          | membersd   | mytext5    |
+-------------+------------+------------+

table2
+-------------+----------+------------+-------------+
|meta_id      |  post_id | meta_key   | meta_value  |
+-------------+----------+------------+-------------+
| 1           |  15      | membersg   |             |
| 2           |  15      | membersb   |             | 
| 3           |  15      | membersd   |             |
| 4           |  16      | membersg   |             |
| 5           |  16      | membersb   |             |
| 6           |  16      | membersd   |             |
+-------------+----------+------------+-------------+


AFTER:

table2
+-------------+----------+------------+-------------+
|meta_id      |  post_id | meta_key   | meta_value  |
+-------------+----------+------------+-------------+
| 1           |  15      | membersg   |  mytext     |
| 2           |  15      | membersb   |  mytext2    | 
| 3           |  15      | membersd   |  mytext3    |
| 4           |  16      | membersg   |  mytext4    |
| 5           |  16      | membersb   |  mytext5    |
| 6           |  16      | membersd   |  mytext6    |
+-------------+----------+------------+-------------+

Can this be done with a query (perhaps inside phpmyadmin)? I have MySQL and phpmyadmin locally on Linux and also MySQL Workbench.

Options: ReplyQuote


Subject
Written By
Posted
MySQL copy fields based on conditions
June 17, 2015 12:22PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.