Is it possible to use join and arithmetic operator in single mysql update query?

Viewed 43

I Have two tables 1st is prodstock and 2nd is orderDetails like following

  1. prodstock table

enter image description here

  1. OrderDetails Table enter image description here

I want to use a query that when I update the status of the order table and deliver, the quantity of my product table should also decrease by the amount of quantity in the order table, now I don't know how to do it.

1 Answers

**Thanks for helping ** I make that perfect query which is work for me I am sharing with you:-

UPDATE prodstock 
INNER JOIN orderdetails ON prodstock.cat_id = orderdetails.cat_id AND
           prodstock.dyenumber = orderdetails.dyenumber 
SET prodstock.total_stock = prodstock.total_stock - orderdetails.qty
WHERE orderdetails.order_id = 2;

I think you guys also have to see this

Related