Mysql必读mysql中You can’t specify target table for update in FROM clause错误解决方法

Mysql必读mysql中You can’t specify target table for update in FROM clause错误解决方法,第1张

概述介绍《Mysql必读mysql中You can’t specify target table for update in FROM clause错误解决方法》开发教程,希望对您有用。

《MysqL必读MysqL中You can’t specify target table for update in FROM clause错误解决方法》要点:
本文介绍了MysqL必读MysqL中You can’t specify target table for update in FROM clause错误解决方法,希望对您有用。如果有疑问,可以联系我们。

MysqL中You can't specify target table for update in FROM clause错误的意思是说,不能先select出同一表中的某些值,再update这个表(在同一语句中). 例如下面这个sql:
MysqL数据库

代码如下:
delete from tbl where ID in
(
        select max(ID) from tbl a where EXISTS
        (
            select 1 from tbl b where a.tac=b.tac group by tac HAVING count(1)>1
        )
        group by tac
)

改写成下面就行了:MysqL数据库

代码如下:
delete from tbl where ID in
(
    select a.ID from
    (
        select max(ID) ID from tbl a where EXISTS
        (
            select 1 from tbl b where a.tac=b.tac group by tac HAVING count(1)>1
        )
        group by tac
    ) a
)

也便是说将select出的结果再通过中间表select一遍,这样就规避了错误.注意,这个问题只出现于MysqL,mssql和oracle不会出现此问题.MysqL数据库

《MysqL必读MysqL中You can’t specify target table for update in FROM clause错误解决方法》是否对您有启发,欢迎查看更多与《MysqL必读MysqL中You can’t specify target table for update in FROM clause错误解决方法》相关教程,学精学透。内存溢出PHP学院为您提供精彩教程。

总结

以上是内存溢出为你收集整理的Mysql必读mysql中You can’t specify target table for update in FROM clause错误解决方法全部内容,希望文章能够帮你解决Mysql必读mysql中You can’t specify target table for update in FROM clause错误解决方法所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/1154576.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-01
下一篇 2022-06-01

发表评论

登录后才能评论

评论列表(0条)

保存