Multiple Updates in MySQL

前端 未结 17 1443
南方客
南方客 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:40

    Yes, that's possible - you can use INSERT ... ON DUPLICATE KEY UPDATE.

    Using your example:

    INSERT INTO table (id,Col1,Col2) VALUES (1,1,1),(2,2,3),(3,9,3),(4,10,12)
    ON DUPLICATE KEY UPDATE Col1=VALUES(Col1),Col2=VALUES(Col2);
    

提交回复
热议问题