I have two tables that need to have same values from one field , if that values are not same in second table change it to value of first table
Frist table is ps_product and they all need to have same id_product, the value that I need to change or check is id_category_default and if they are not the same put value in ps_product_shop to be same id_category_default as in ps_product
Can that be done for every entry?
Can I do something like; To check if the value is 5 in one table then if in second table for same id is 0, put 5 there, also if there is no such id in second table create it and add values from frist table? To go ver all id's and check if they exist in second table?
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 :
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.