MySQL join update: Updating join table row twice
To explain the problem I have just outlined an example situation below.
OrderRows
ID|OrderNumber|ProductNumber|Quantity|Done 1|10|100|1|no* 2|10|101|1|no
3|10|100|4|no* * Have the same product number
Stock ProductNumber|Quantity 100|5 101|1
UPDATE OrderRows INNER JOIN Stock ON
Stock.ProductNumber=OrderRows.ProductNumber SET Done='yes', Stock.
Quantity = Stock. Quantity -OrderRows. Quantity WHERE OrderNumber='100'
AND Done='no'
The result for the table Stock will be as below.
ProductNumber|Quantity 100|4 101|0
The Order Rows are updated correctly. But for Order Row three the Stock is
not adapted. This is because Order Row three has the same Product Number
as Order Row one. The question is, how can I fix this?
No comments:
Post a Comment