zoukankan      html  css  js  c++  java
  • Mysql更新数据时,报 “You can't specify target table 'message ' for update in FROM clause” 解决办法

    报错的SQL为:

    delete from message where id not in  (select min(id) as id from message group by content)

    报错信息的中文意思为:不能在FROM子句中更新  message表数据,原因是 "不能在从本表中查出数据范围后,然后直接更新本表",

    解决方法思路是,让数据库认为,你查出的数据范围,是不从本表中查出来的,实现步骤如下:

    1、用as,给查出的数据表,设置别名为a,即 (select min(id) as id from message group by content)as a

    2、用别名,查出数据范围,即 select a.id from (select min(id) as id from message group by content)as a

    修改后的完整SQL为

    delete from message where id not in  (select a.id from (select min(id) as id from message group by content) as a)

  • 相关阅读:
    Tomcat域名绑定
    Windows下搭建PHP开发环境
    创业项目该如何选择技术?
    linux mount 挂接新硬盘
    Linux 查看系统硬件信息
    this super的用法
    构造方法
    多态
    抽象类和接口
    继承
  • 原文地址:https://www.cnblogs.com/testeyes/p/11419188.html
Copyright © 2011-2022 走看看