Using PHP and MySQL, I have a query that will look something like this:
UPDATE mytable
SET status='$newstatus'
WHERE (col1='$col1[0]'AND col2='$col2[0]')
OR (col1='$col1[1]'AND col2='$col2[1]')
OR (...);
I actually need to record the current ‘status’ of each of these rows before the update. Do I need to do a separate SELECT before this, or can (should / how would) I combine the two queries?
You cannot get that from this query (you could only get number of affected rows, but that’s it). If you need that, you shall first do
SELECTon your conditions like:and then do
UPDATEwithWHEREusing fetchedids. I do not recommend doingUPDATEwith your currentWHEREclause as in meantime (between yourSELECTandUPDATE) db content could change, so you could be UPDATING different rows that you hadSELECTed. Or use table locking (but I do not think it makes sense here).