错误代码:1093。表'site_html'被指定两次,既作为'UPDATE'的目标又作为数据的单独来源

时间:2016-06-13 03:07:59

标签: mysql sql

我想用各自的id更新表的'status'列,但它会导致我输入错误代码1093。 下面是我的SQL查询

Update site_html Set status='Update Found' 
Where id = (
            select id 
            from site_html
            where link='http://www.example.com'); 

如何更正此错误?我是SQL的新手。

1 个答案:

答案 0 :(得分:3)

在MySQL中,您无法直接修改在SELECT部分​​中使用的相同表名。所以你可以通过表别名来完成它。

update site_html AS s, (select id  from site_html where link='http://www.example.com') AS t
set status='Update Found' 
where s.id = t.id;