I'm stumped. I have read a lot of different questions similar to this, but still can't figure things out.
Here is a snippet of the before table. (POs_Parts)
+-------+------------+----------+---------+-------+----------+
| p_Key | f_key_part | f_key_po | partQty | r_qty | r_author |
+-------+------------+----------+---------+-------+----------+
| 0 | 18 | 6 | 2 | 0 | NULL |
| 1 | 19 | 6 | 3 | 0 | NULL |
| 2 | 20 | 6 | 1 | 0 | NULL |
| 3 | 18 | 8 | 1 | 0 | NULL |
+-------+------------+----------+---------+-------+----------+
Here is how I would like it to be after the update statements. (The last two columns have been updated)
+-------+------------+----------+---------+-------+----------+
| p_Key | f_key_part | f_key_po | partQty | r_qty | r_author |
+-------+------------+----------+---------+-------+----------+
| 0 | 18 | 6 | 2 | 2 | John |
| 1 | 19 | 6 | 3 | 2 | John |
| 2 | 20 | 6 | 1 | 0 | John |
| 3 | 18 | 8 | 1 | 1 | John |
+-------+------------+----------+---------+-------+----------+
I think that this statement does what I want - for one row - but I have tons of rows that need to be changed at a time, so I'd like to avoid executing a lot of statements one at a time.
UPDATE POs_Parts SET r_qty = 2, r_author='John' where f_key_part = 18 and f_key_po = 6;
Here is the question I was trying to use as a reference. Multiple Updates in MySQL
How can I rewrite this without having to run a bunch of Update
statements? I will be using PHP
to create the query. Any suggestions would be appreciated.