Here is my table structure:
table
.id
(auto increment; primary key)
table
.qty
( possible values: 0 - 1000 )
Rows:
+----+-----+ | id | qty | +----+-----+ | 1 | 0 | | 2 | 5 | | 3 | 5 | | 4 | 10 | +----+-----+
I want to decrease the quantity available by 12. Meaning, the new result should be:
Edit: I probably should have specified all these numbers are arbitrary. They could be anything.
+----+-----+ | id | qty | +----+-----+ | 1 | 0 | | 2 | 0 | | 3 | 0 | | 4 | 8 | +----+-----+
Right now, I do the following:
SELECT id, qty FROM table WHERE qty > 0 LIMIT 12
Filter through all the data to figure out what qty to remove from each row
Use a PDO prepared statement to mass update the affected rows:
UPDATE `table` SET qty = ? WHERE id = ?`
My question: Is there a way to do this all in MySQL?