开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜