I would like to update multiple rows in one single query by using UPDATE CASE scenario in mySQL. I am building my web app using python and Django. Here is my code:
UPDATE order
SET priority_number =
CASE priority_number
WHEN 2 THEN 3
WHEN 3 THEN 4
WHEN 1 THEN 5
WHEN 4 THEN 2
WHEN 5 THEN 1
END
So this single query will update all field as I desire. My question is, how can I program this if I have an unknown number of rows to update? Lets say all these numbers comes from an array that I will pass into my views and I don’t know how many WHEN and THEN statement I need to write? thanks for your help!