最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

mysql 一個較特殊的問題:You can't specify target table 'wms_cabinet_form'

 更新時間:2010年11月30日 21:31:34   作者:  
mysql 一個較特殊的問題:You can't specify target table 'wms_cabinet_form' for update in F
今天在寫 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)

運(yùn)行時提出如下提示: You can't specify target table 'wms_cabinet_form' for update in FROM clause

運(yùn)行 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 正確結(jié)果。再把結(jié)果直接寫到 in 里面,改后語句如下:
update wms_cabinet_form set cabf_enabled=0 where cabf_id in ('113','114','115'),再運(yùn)行可以正確執(zhí)行更新。
到這一步開始想不明白,為什么用 select 子句運(yùn)行會出錯呢?以前在 mssql 這種寫法是很常見的。
沒辦法了,唯有動用 baidu。找到兩條記錄。

原來原因是:mysql中不能這么用。 (等待mysql升級吧)。那串英文錯誤提示就是說,不能先select出同一表中的某些值,
再update這個表(在同一語句中)。 也找到替代方案,重寫改寫了 sql 。

改寫后的 sql 如下所示,大家仔細(xì)區(qū)別一下。

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)

重點(diǎn)在 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 都是同一個表。致此問題得到完美解決。

相關(guān)文章

最新評論

商河县| 浦北县| 民权县| 宁阳县| 江北区| 水富县| 宁晋县| 赤城县| 新巴尔虎右旗| 富宁县| 铜川市| 社会| 达州市| 莎车县| 临夏县| 伊宁县| 奉节县| 武平县| 沂水县| 横峰县| 多伦县| 湛江市| 平泉县| 承德县| 娄烦县| 岗巴县| 呼图壁县| 会昌县| 丹寨县| 从江县| 武威市| 尚志市| 泰顺县| 安溪县| 惠安县| 龙陵县| 中宁县| 上思县| 德江县| 阳江市| 固安县|