开发者

MySQL possible to update multiple rows with different where clause, single query

开发者 https://www.devze.com 2023-03-20 18:53 出处:网络
Is is possible to have one query update multiple columns with different where clauses for example, can you combine this?

Is is possible to have one query update multiple columns with different where clauses for example, can you combine this?

update tblTest set price = '5000'开发者_如何学编程 where id = '2'

update tblTest set price = '3000' where id = '3'

update tblTest set price = '4000' where id = '4'

how would you combine those 3 queries to one query?


I think it's

UPDATE `tblTest` SET `price` = CASE `Id` 
    WHEN 2 THEN 5000
    WHEN 3 THEN 3000
    WHEN 4 THEN 4000
END CASE;
0

精彩评论

暂无评论...
验证码 换一张
取 消