updating MySQL table - You can't specify target table for update in From
clause
I have the following query:
SELECT entity_id AS product_id FROM catalog_product_entity cpe
LEFT JOIN cataloginventory_stock_item csi ON csi.product_id = cpe.entity_id
WHERE cpe.type_id = 'configurable'
AND csi.is_in_stock = 0
AND (SELECT SUM(qty) FROM catalog_product_relation cpr LEFT JOIN
cataloginventory_stock_item cisi ON cisi.product_id = cpr.child_id WHERE
cpr.parent_id = cpe.entity_id) > 0
Which returns the following results:
product_id
-----------
912
906
894
559
364
I am trying to update the is_in_stock column within the
cataloginventory_stock_item table, based off of the product_id of the
table existing in the results of the above query.
What I tried to do was this:
UPDATE cataloginventory_stock_item
SET is_in_stock = 1
WHERE product_id IN (
SELECT entity_id AS product_id FROM catalog_product_entity cpe
LEFT JOIN cataloginventory_stock_item csi ON csi.product_id =
cpe.entity_id
WHERE cpe.type_id = 'configurable'
AND csi.is_in_stock = 0
AND (SELECT SUM(qty) FROM catalog_product_relation cpr LEFT JOIN
cataloginventory_stock_item cisi ON cisi.product_id = cpr.child_id
WHERE cpr.parent_id = cpe.entity_id) > 0
)
And I receive the following error:
You can't specify target table 'cataloginventory_stock_item' for update in
FROM clause
I can't seem to figure out how to restructure the query to work. Any help
is greatly appreciated.
No comments:
Post a Comment