I need to take value ecotax from table ps_product for id_product and update value ecotax on same id_product in table ps_product_shop.
Make this command:
UPDATE `ps_product_shop`
SET `ecotax` = (SELECT `ecotax` FROM `ps_product`
WHERE ps_product.`id_product` =
ps_product_shop.`id_product`);
but get:
#1048 – Column ‘ecotax’ cannot be null
values are 0.0000 or 0.1580 and so on. As well tried IN NOT NULL in SELECT but didnt help. Command is processed by phpMyAdmin.
Any idea please?
2
Answers
You can follow two ways:
The first:
The second:
The only possible reason I can conjure up to explain this is that you’re not qualifying
ecotax
inside the subquery with a proper alias. Try doing that:But I actually recommending taking advantage of MySQL’s update join syntax here (assuming you’re actually using MySQL):