I have two tables
oc_stock_hpp
id product_id stock
2 1234 0
3 5678 0
4 1234 0
6 1234 0
9 5678 0
oc_product
id product_id quantity
1 1234 7
23 5678 9
My purpose is to update value in the stock field table oc_stock_hpp where id=6 become 7 and id=9 become 9 as in oc_product table
I have tried
UPDATE oc_stock_hpp t1
INNER JOIN oc_product t2
ON t1.product_id = t2.product_id
SET t1.stock = t2.quantity
WHERE t1.id = (SELECT MAX(id) FROM oc_stock_hpp GROUP BY product_id)
and got error Subquery returns more than 1 row