[英]Combine UPDATE query into one single query for SQL
I have these queries, I would like to combine these queries into one without running this 2 times.我有这些查询,我想将这些查询合并为一个而不运行 2 次。 I tried combining this with the
OR
condition?我尝试将其与
OR
条件结合起来? Is this the best way to do this?这是最好的方法吗?
UPDATE `table_name` SET `item` = 'abc' WHERE `name` = 'apple' OR `name` = 'orange';
UPDATE `table_name` SET `item` = 'abc' WHERE `name` = 'apple';
UPDATE `table_name` SET `item` = 'abc' WHERE `name` = 'orange';
Thanks.谢谢。 if you don't like OR operator you could try an IN clause
如果您不喜欢 OR 运算符,可以尝试使用 IN 子句
UPDATE table_name
SET item = 'abc'
WHERE name IN ( 'apple' , 'orange');
pratically there are the same..实际上有相同的..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.