Issue
I have two tables:
What I needs is SQL query that I can run via the SQL tab in phpMyAdmin, which will sum the "options_stock" from "table_options" based on the "product_id", and it will write that sum number into "main_stock" in "table_products" for the corresponding "product_id", so the "table_products" will look like this:
Thanks in advance.
Solution
Try the below - with update join
update table_product p
join
(select product_id, sum(options_stock) as options_stock from
table_options group by product_id
) o on p.product_id=o.product_id
set main_stock=options_stock
Answered By - Fahmi
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.