首页 > 代码库 > mysql 更新sql报错:You can't specify target table 'wms_cabinet_form' for update in FROM clause
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
mysql 更新sql报错:You can't specify target table 'wms_cabinet_form' for update in FROM clause