I believe you are thinking sequential here, and dbs are powerfull only when they process bulk data.
What you should do is join the tables in an update statement with id_product as key and a where that will filter only the records where ps_product_shop <> id_category_default.
It should look like :
update table_name2
set ps_product_shop = id_category_default
from table_name1 inner join table_name2 on table_name1.id_product = table_name2.id_product
where ps_product_shop <> id_category_default
This is in MS SQL syntax, so you might need to change it a bit for MySql.
After you've updated the records where ps_product_shop doesn't match the id_category_default, then you should insert the missing records.
Again I would use join:
insert into table_name2 (field1, field2, field3)
select field1, field2, field3 from table_name1 left join table_name2
on table_name1.id_product = table_name2.id_product
and ps_product_shop = id_category_default
where table_name2.id_product is null
The above will join the 2 tables and then filter out the records that have in both tables same id_product and ps_product_shope = id_category_default.
adam_k
Veteran Poster
1,057 posts since Jun 2011
Reputation Points: 274
Solved Threads: 205
Skill Endorsements: 11
Did you get an error?
What do you mean no luck?
Did ps_producy_shop contain any of the id_category_default you were trying to insert?
adam_k
Veteran Poster
1,057 posts since Jun 2011
Reputation Points: 274
Solved Threads: 205
Skill Endorsements: 11
Question Answered as of 4 Months Ago by
adam_k