我發現這個語法用一個查詢更新2個mysql行。它看起來很棒,但我無法按照自己想要的方式工作。更新2使用CASE WHENEN的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
謝謝,我忘了結束。 :) – Buddy