菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
116
0

mysql 更新sql报错:You can't specify target table 'wms_cabinet_form' for update in FROM clause

原创
05/13 14:22
阅读数 59420

    数据库里面有两个字段的位置不对,要把他们对调换下。因为没有数据库写的权限,需要用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

发表评论

0/200
116 点赞
0 评论
收藏