Update multiple columns for multiple rows in one query of SQL

后端 未结 2 1750
感动是毒
感动是毒 2020-12-30 01:37

I am trying to set multiple columns for multiple rows in one query, but so far no luck.

Here\'s how my table looks like

Table: user

2条回答
  •  囚心锁ツ
    2020-12-30 02:04

    You can also hack the insert operation :

    INSERT INTO mytable (id, a, b, c)
    VALUES (1, 'a1', 'b1', 'c1'),
    (2, 'a2', 'b2', 'c2'),
    (3, 'a3', 'b3', 'c3'),
    (4, 'a4', 'b4', 'c4'),
    (5, 'a5', 'b5', 'c5'),
    (6, 'a6', 'b6', 'c6')
    ON DUPLICATE KEY UPDATE id=VALUES(id),
    a=VALUES(a),
    b=VALUES(b),
    c=VALUES(c)
    

提交回复
热议问题