I have a table 1 in wordpress as
wp_term_relationships (
object_id bigint(20),
term_taxonomy_id bigint(20),
term_order int(11)
)
and table 2 as
wp_test (
object_id bigint(20),
term_taxonomy_id bigint(20)
)
Now I am trying to update wp_term_relationships with the values in wp_test as
update ignore wp_term_relationships m1
inner join wp_test m2
on (m1.term_taxonomy_id = m2.term_taxonomy_id)
set m1.object_id = m2.object_id
However, all the values of wp_test do not get updated to wp_term_relationships
I have even tried straight up inserting the values from wp_test into wp_test_relationships
by using an insert as
insert ignore into wp_term_relationships(object_id, term_taxonomy_id)
select object_id, term_taxonomy_id from wp_test
But it just updates the term_taxonomy_id values with the corresponding object_id values as 0 or
object_id values with the corresponding term_taxonomy_id values as 0
How can I transfer these 2 columns from wp_test into wp_term_relationships
I think what you need is an
INSERTwithoutIGNOREand withON DUPLICATE KEY UPDATEinstead:Note that this assumes that you have a unique constraint on wp_term_relationships.object_id
edit for different case:
If you mean that what constitutes a "duplicate" is a distinct combination of the two columns, then you need to add a unique constraint on the two columns in MySQL, and then use your
INSERT IGNOREquery: