Mysql 为选定ID更新表中的多行
我有一个表“table1”,需要更新。 我有一个查询,将提取需要更新的所需id。 e、 g 我试过了Mysql 为选定ID更新表中的多行,mysql,sql,Mysql,Sql,我有一个表“table1”,需要更新。 我有一个查询,将提取需要更新的所需id。 e、 g 我试过了 UPDATE table1 set col1=0 where id=**query that lists id** [Didn't worked] UPDATE table1 set col1=0 where id in **query that lists id** [Didn't worked] 如何更新表中从另一个查询中提取的ID数 *注: 使用MySQL 我从中提取ID的子查询还涉
UPDATE table1 set col1=0 where id=**query that lists id** [Didn't worked]
UPDATE table1 set col1=0 where id in **query that lists id** [Didn't worked]
如何更新表中从另一个查询中提取的ID数
*注:
使用MySQL
我从中提取ID的子查询还涉及“table1”和
上面说,,
当前,您无法更新表并从子查询中的同一表中进行选择。使用
update table1 set col1 = 0 where id in (select id from tablen)
试一试
UPDATE table1 set col1=0 where id in (select id from <someothertable>)
在MySQL中,最有效的方法可能是使用join:
如果选择ID的查询实际使用表1,这也会起作用。作用如下: 创建表id_TABLE作为SOME-QUERY-HERE-THAT-WILL-SPIT-REQD-ids; 更新table1 SET col1=0,其中id在SELECT id from ids_table中; 删除表id_表; 这个想法似乎不是一个好的做法,但它奏效了
UPDATE table1 set col1=0 where id in (select id from <someothertable>)
UPDATE table1 toupdate join
(select id
from <someothertable>
) sot
on toupdate.id = sot.id
set toupdate.col1 = 0;