在MySQL中更新数据给出了错误

时间:2014-03-12 05:27:43

标签: mysql

update table1 
set isDeleted = 1 
where isDeleted = 0 
and mId in (select id from table1 where isDeleted = 1 );

错误代码:1093。您无法指定目标表' table1'用于FROM子句中的更新

1 个答案:

答案 0 :(得分:2)

使用联接:

UPDATE table1 t1
JOIN table1 t2 ON t1.mId = t2.id
SET t1.isDeleted = 1
WHERE t1.isDeleted = 0
AND t2.isDeleted = 1