Updating multiple rows with different values

前端 未结 3 2064
忘了有多久
忘了有多久 2020-12-31 19:07

I got this table in my MySQL database, \'users\'. It has the fields \'id\' and \'value\'.

Now, I want to update lots of rows in this table with a single

3条回答
  •  [愿得一人]
    2020-12-31 19:23

    I would just do this with a few different UPDATE statements.

    UPDATE users
        SET value = 53
    WHERE id = 1;
    
    
    UPDATE users
        SET value = 65
    WHERE id = 2;
    
    ...
    

    This seems simplest if you only have 5 or 6 values to set on multiple rows each. Or is there some specific reason that you need to do this in one query?

提交回复
热议问题