程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MySQL綜合教程 >> mysql 一個較特別的成績:You cant specify target table wms_cabinet_form

mysql 一個較特別的成績:You cant specify target table wms_cabinet_form

編輯:MySQL綜合教程

mysql 一個較特別的成績:You can't specify target table 'wms_cabinet_form'。本站提示廣大學習愛好者:(mysql 一個較特別的成績:You can't specify target table 'wms_cabinet_form')文章只能為提供參考,不一定能成為您想要的結果。以下是mysql 一個較特別的成績:You can't specify target table 'wms_cabinet_form'正文


明天在寫 mysql 碰到一個比擬特別的成績。
mysql 語句以下:

update wms_cabinet_form set cabf_enabled=0
where cabf_id in (
SELECT wms_cabinet_form.cabf_id FROM wms_cabinet_form
Inner Join wms_cabinet ON wms_cabinet_form.cabf_cab_id = wms_cabinet.cab_id
Inner Join wms_cabinet_row ON wms_cabinet.cab_row_id =wms_cabinet_row.row_id
where wms_cabinet_row.row_site_id=27 and wms_cabinet_form.cabf_enabled=1)

運轉時提出以下提醒: You can't specify target table 'wms_cabinet_form' for update in FROM clause

運轉 in 外面的 select 字句:

SELECT wms_cabinet_form.cabf_id FROM wms_cabinet_form
Inner Join wms_cabinet ON wms_cabinet_form.cabf_cab_id = wms_cabinet.cab_id
Inner Join wms_cabinet_row ON wms_cabinet.cab_row_id =wms_cabinet_row.row_id
where wms_cabinet_row.row_site_id=27 and wms_cabinet_form.cabf_enabled=1

可以准確 select 准確成果。再把成果直接寫到 in 外面,改後語句以下:
update wms_cabinet_form set cabf_enabled=0 where cabf_id in ('113','114','115'),再運轉可以准確履行更新。
到這一步開端想不明確,為何用 select 子句運轉會失足呢?之前在 mssql 這類寫法是很罕見的。
沒方法了,惟有動用 百度。找到兩筆記錄。

本來緣由是:mysql中不克不及這麼用。 (期待mysql進級吧)。那串英文毛病提醒就是說,不克不及先select出統一表中的某些值,
再update這個表(在統一語句中)。 也找到替換計劃,重寫改寫了 sql 。

改寫後的 sql 以下所示,年夜家細心差別一下。

update wms_cabinet_form set cabf_enabled=0 where cabf_id in (
SELECT a.cabf_id FROM (select tmp.* from wms_cabinet_form tmp) a
Inner Join wms_cabinet b ON a.cabf_cab_id = b.cab_id
Inner Join wms_cabinet_row c ON b.cab_row_id = c.row_id
where c.row_site_id=29 and a.cabf_enabled=1)

重點在 SELECT a.cabf_id FROM (select tmp.* from wms_cabinet_form tmp) a ,我 select tmp.* from wms_cabinet_form tmp 作為子集,
然後再 select a.cabf_id FROM 子集,如許就不會 select 和 update 都是統一個表。致此成績獲得完善處理。
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved