0
我試圖運行一個UPDATE連接到其他表,並在WHERE子句中有一個子查詢。不過,我得到這個錯誤:使用JOIN和子查詢更新表
1093 - You can't specify target table 'csi' for update in FROM clause
這裏是我的查詢:
UPDATE mage_cataloginventory_stock_item csi
INNER JOIN mage_catalog_product_entity cpe
ON csi.product_id = cpe.entity_id
SET csi.Is_in_Stock = 0
WHERE cpe.sku IN (
SELECT cpe.sku
FROM mage_catalog_product_entity cpe
INNER JOIN mage_cataloginventory_stock_item CSI
ON CSI.product_id = cpe.entity_id
INNER JOIN mage_cataloginventory_stock_status CISS
ON CSI.product_id = CISS.product_ID
INNER JOIN mage_catalog_product_entity_int cpei
ON cpe.entity_id = cpei.entity_id
WHERE type_id = 'simple'
AND cpei.attribute_id = 80
AND CSI.Qty = 0 AND cpei.value = 1
)
我從其他渠道看到你不能指定表中的子查詢更新,但我不知道如何做到這一點..希望有人能幫助指點我在正確的方向,讓我的需要這個工作。謝謝!
非常感謝。後者查詢工作得很好。有時候我陷入了過於複雜的sql ..需要額外的眼睛:) –