1 つのクエリで 2 つの mysql 行を更新するためのこの構文を見つけました。素晴らしいロジックのように見えますが、思い通りに動作させることができません。
この構文が間違っているかどうか誰かが教えてくれたら、とてもありがたいです。私はこれを正しく理解していますか?
$id_active = 1;
$id_swap = 2;
UPDATE article_test
// the column to update is 'sort_id' and since it is also the column I need to test, then I use the same value for CASE right?
SET sort_id = CASE sort_id
WHEN $id_active THEN $id_swap // sort_id 1 to become sort_id 2
WHEN $id_swap THEN $id_active // sort_id 2 to become sort_id 1
WHERE sort_id IN ($id_swap,$id_active) // test only rows with sort_id 1 & sort_id 2