Multiple Updates in MySQL

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

    You may also be interested in using joins on updates, which is possible as well.

    Update someTable Set someValue = 4 From someTable s Inner Join anotherTable a on s.id = a.id Where a.id = 4
    -- Only updates someValue in someTable who has a foreign key on anotherTable with a value of 4.
    

    Edit: If the values you are updating aren't coming from somewhere else in the database, you'll need to issue multiple update queries.

提交回复
热议问题