Skip to content
Advertisement

SQL – copy data from one table column to another table column

As you can see from the image I have a table called wpw8_postmeta where it has four columns and I have searched for the term release and got the following results.

I want to copy the results (release_date [meta_value]) to another table called wpw8_test using the post_id as foreign key/primary key.

enter image description here

The second table looks like this

enter image description here

After the update will be done it should look like this

enter image description here

Advertisement

Answer

You seem to be looking for the update ... join syntax:

update wpw8_test t
inner join wpw8_postmeta p on p.post_id = t.post_id
set t.release_date = p.meta_value
where p.meta_key like '%release%'
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement