Multiple Updates in MySQL

前端 未结 17 1356
南方客
南方客 2020-11-22 01:31

I know that you can insert multiple rows at once, is there a way to update multiple rows at once (as in, in one query) in MySQL?

Edit: For example I have the followi

17条回答
  •  深忆病人
    2020-11-22 01:41

    And now the easy way

    update my_table m, -- let create a temp table with populated values
        (select 1 as id, 20 as value union -- this part will be generated
         select 2 as id, 30 as value union -- using a backend code
         -- for loop 
         select N as id, X as value
            ) t
    set m.value = t.value where t.id=m.id -- now update by join - quick
    

提交回复
热议问题