mysql同时update多行
-
当我们只更新一个字段时的语法如下:
UPDATE mytableSET myfield = CASE other_fieldWHEN 1 THEN 'value'WHEN 2 THEN 'value'WHEN 3 THEN 'value'ENDWHERE id IN (1,2,3) -
当我们只更新多个字段时的语法如下:
UPDATE categoriesSET display_order = CASE idWHEN 1 THEN 3WHEN 2 THEN 4WHEN 3 THEN 5END,title = CASE idWHEN 1 THEN 'New Title 1'WHEN 2 THEN 'New Title 2'WHEN 3 THEN 'New Title 3'ENDWHERE id IN (1,2,3)