【问题标题】:PHP mysql update multiple row by single query SET='101' where id =1,2,3,7,9PHP mysql 通过单个查询更新多行 SET='101' where id =1,2,3,7,9
【发布时间】:2015-01-16 06:29:22
【问题描述】:

我正在尝试更新 mysql 中的行,但对于单值 mysql 查询,我必须使用 for 循环进行多次更新

update table set column1='100' where id =1
update table set column1='100' where id =6
update table set column1='100' where id =14

我正在使用 for 循环多次运行具有不同 ID 的查询,我想运行单个查询以更新所有行。这可能吗?

我想做这样的事情

  update table set column1='100' where id=1,6,14;

【问题讨论】:

  • @saharsh:实际上不希望像 [whree-clause] 那样添加尽可能多的标签。这并没有真正增加问题的任何内容。

标签: mysql sql sql-update where-clause in-operator


【解决方案1】:

使用IN()

update table 
set column1='100' 
where id in (1,6,14)

OR

update table 
set column1='100' 
where id = 1 OR id = 6 OR id = 14

【讨论】:

    【解决方案2】:

    使用 IN() 运算符

    update table_name SET field_name='101'
    where id IN(1,2,7,9) 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-02
      • 1970-01-01
      • 2010-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多