使用一个SQL请求更新多行

时间:2017-08-23 10:58:54

标签: php mysql pdo

如何使用一个SQL请求更新10行

UPDATE gallery_photos SET queue=:queue WHERE id = :id AND SET queue=:queue2 WHERE id = :id2";

类似这样的事情

1 个答案:

答案 0 :(得分:2)

你可以这样做:

UPDATE gallery_photos
    SET queue = (CASE WHEN id = :id THEN :queue
                      WHEN id = :id2 THEN :queue2
                      ELSE queue  -- strictly speaking, this is not not be necessary because of the outer `WHERE`
                 END)
    WHERE id IN (:id, :id2);