需求:将表(tableA)里面的字段column1值为33的改为22
错误示例
错误提示是:ERROR 1093 (HY000): You can't specify target table 'apples' for update in FROM clause. MySQL手册[UPDATE documentation](http://dev.mysql.com/doc/refman/5.0/en/update.html)这下面有说明 : “Currently, you cannot update a table and select from the same table in a subquery.”
在这个例子中,要解决问题也十分简单,但有时候不得不通过查询子句来update目标。好在我们有办法。
正确示例:
错误示例
update tableA set column1='22'
where uid in (
select uid from tableA where column1='33'
)
错误提示是:ERROR 1093 (HY000): You can't specify target table 'apples' for update in FROM clause. MySQL手册[UPDATE documentation](http://dev.mysql.com/doc/refman/5.0/en/update.html)这下面有说明 : “Currently, you cannot update a table and select from the same table in a subquery.”
在这个例子中,要解决问题也十分简单,但有时候不得不通过查询子句来update目标。好在我们有办法。
正确示例:
update tableA set column1='22'
where uid in (
select uid from (
select uid from tableA where column1='33'
) tmp
)
版权申明:本文为博主原创文章,未经博主允许不得转载。
https://www.leftso.com/blog/852.html
时效提示:本文最后更新于【 2021-09-02 17:21:35 】,某些文章具有时效性,若有错误或已失效,请在下方留言。
时效提示:本文最后更新于【 2021-09-02 17:21:35 】,某些文章具有时效性,若有错误或已失效,请在下方留言。
评论区域
评论功能已关闭. 提示:评论功能虽已关闭,关闭之前的评论仍然会展示。