I am trying to update all the values in one table that exist in a second table, once for each occurence.
Example feeding_view table:
fishnr | food_name | stock
-------+-----------+-------
1 | f1 | 25
2 | f1 | 25
3 | f2 | 30
Example inventory table:
item_name | stock
----------+-------
f1 | 25
f2 | 30
f3 | 10
Currently I am trying to do this:
UPDATE inventory SET stock = stock - 1 WHERE item_name IN (SELECT food_name FROM feeding_view)
What happens is f1 only gets decremented a single time but I want it to decrement for each each f1 in the feeding_view. So the desired stock for f1 is 23 and for f2 is 29 but instead f1 is only decremented once to 24.
or maybe this, not sure: