MySQL UPDATE with SELECT SUM from different table MySQL UPDATE with SELECT SUM from different table sql sql

MySQL UPDATE with SELECT SUM from different table


You can UPDATE with JOINing the two tables:

UPDATE Orders o INNER JOIN(   SELECT order_id, SUM(qt * unit_price) 'sumu'   FROM items    GROUP BY order_id) i ON o.id = i.order_idSET o.total_price = i.sumu[WHERE predicate]