zoukankan      html  css  js  c++  java
  • mysql 更新sql报错:You can't specify target table 'wms_cabinet_form' for update in FROM clause

        数据库里面有两个字段的位置不对,要把他们对调换下。因为没有数据库写的权限,需要用sql语句来实现。原来以为简单的

      update table a set a.字段a=(select b字段 from table  where id=?) ,set a.字段b=(select a字段 from table where id=?) where id=? ,结果报了 这个问题

      You can't specify target table 'wms_cabinet_form' for update in FROM clause

     google 之后发现是mysql本身的问题,需要这样来写:

    update  table set  字段a=(select t1.字段b from (select * from table where id=?)t1),set 字段b=(selet t2.字段a from (select * from table where id=?)t2) where id=?

    自己的为例:

    UPDATE ec_payment_type
    SET return_url = (
    SELECT
    a.notify_url
    FROM
    (
    SELECT
    *
    FROM
    ec_payment_type
    WHERE
    payment_type_id = 10
    ) a
    ),
    notify_url = (
    SELECT
    b.return_url
    FROM
    (
    SELECT
    *
    FROM
    ec_payment_type
    WHERE
    payment_type_id = 10
    ) b
    )
    WHERE
    payment_type_id = 10

  • 相关阅读:
    六 . 爬虫 Xpath介绍和使用
    五. 爬虫 正则表达式
    四 . 爬虫 BeautifulSoup库参数和使用
    三 . 爬虫 url编码
    一 . 爬虫
    【HDU5952】Counting Cliques
    【HDU5521】Meeting
    【模板】回文自动机
    【CF1218E】Product Tuples
    【洛谷P2485】计算器
  • 原文地址:https://www.cnblogs.com/thinkingandworkinghard/p/6344395.html
Copyright © 2011-2022 走看看