Visnu Carr
Visnu Carr

Reputation: 1

Copy specific column data from one table to another table column? (Wordpress PhPMyAdmin)

Been googling, testing and searching for hours to no avail...I'm hoping someone here can help me with what I presume is a fairly simple SQL command, but I'm very basic about it and just getting errors.

My situation is as follows: I need to take certain row data from wp_postmeta table and stuff it into certain row data into wp_posts. I'm migrating some 50,000 orders from drupal to wordpress, but due to weirdness, order #'s don't match up.

What I am looking to do is copy the meta_value in the wp_postmeta table, but only where meta_key LIKE "_fgd2wp_old_uc_order_id"

Then take this specific query and dump it into wp_posts table, into the ID column, but only where post_type LIKE shop_order.

I can find the data I want through the below search queries...but unsure how to copy. Tried and failed. Any help would be greatly appreciated. Thanks!

SELECT meta_value FROM wp_postmeta WHERE meta_key LIKE '%old_uc_order_id%' SELECT ID FROM wp_posts WHERE post_type LIKE 'shop_order'

Tried this command...but it errors saying WHERE isn't expected. Not sure how to specify what i need?

INSERT INTO wp_posts (ID) WHERE post_type = 'shop_order' SELECT meta_value WHERE meta_key = '_fgd2wp_old_uc_order_id' FROM wp_postmeta;

Upvotes: 0

Views: 126

Answers (2)

Sa786
Sa786

Reputation: 1

To achieve the desired migration of data from the wp_postmeta table to the wp_posts table, you can use the following SQL query:INSERT INTO wp_posts (ID) SELECT meta_value FROM wp_postmeta WHERE meta_key LIKE '_fgd2wp_old_uc_order_id' AND EXISTS ( SELECT 1 FROM wp_posts WHERE post_type LIKE 'shop_order' AND ID = wp_postmeta.post_id );

Upvotes: 0

Evil Genuis
Evil Genuis

Reputation: 11

try this INSERT INTO target_table (column1, column2) SELECT column1, column2 FROM source_table

Upvotes: 0

Related Questions