zoukankan      html  css  js  c++  java
  • 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这个表(在同一语句中)。

    UPDATE bus_clew SET clew_status = '3' WHERE
    id IN (
    SELECT
    c.id
    FROM
    bus_clew c,
    bus_clew_keeper k
    WHERE
    c.id = k.clew_id
    AND c.clew_status = 0
    AND c.is_del = 0
    AND EXISTS (
    SELECT
    1
    FROM
    bus_clew_track t
    WHERE
    t.clew_id = c.id
    AND t.keeper_id = k.keeper_id
    AND t.is_del = 0
    )
    );
     
    要改成下面:
    UPDATE bus_clew SET clew_status = '3' WHERE
    id IN (
     
    select c1.id from (
    SELECT
    c.id
    FROM
    bus_clew c,
    bus_clew_keeper k
    WHERE
    c.id = k.clew_id
    AND c.clew_status = 0
    AND c.is_del = 0
    AND EXISTS (
    SELECT
    1
    FROM
    bus_clew_track t
    WHERE
    t.clew_id = c.id
    AND t.keeper_id = k.keeper_id
    AND t.is_del = 0
    )) c1
    );
    

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

    定位问题原因* 根据原因思考问题解决方案* 实践验证方案有效性* 提交验证结果
  • 相关阅读:
    Appium环境搭建(Mac版)
    html进阶css(1)
    HTML 表单与输出
    HTML 表格入门
    html图像入门
    LAMP_源码安装全教程
    构建高性能的MYSQL数据库系统-主从复制
    apache 服务器配制
    KickStart 无人值守安装系统
    zabbix 3.0 完全安装全解!
  • 原文地址:https://www.cnblogs.com/jimoliunian/p/12975258.html
Copyright © 2011-2022 走看看