1

I have a select query to get data like this:

SELECT cpe.entity_id,
       cpe.type_id,
       cpe.sku,
       cped.value AS "PRICE"

FROM catalog_product_entity AS cpe

LEFT JOIN catalog_product_entity_decimal AS cped 
ON cped.entity_id = cpe.entity_id

WHERE cpe.type_id = 'configurable' AND cped.attribute_id = 77

Now I want to update my cped.value column to null for all row, I tried update query like this:

UPDATE 
    cped
SET
    cped.value = NULL
FROM 
    catalog_product_entity AS cpe
    LEFT JOIN catalog_product_entity_decimal AS cped 
    ON cped.entity_id = cpe.entity_id
WHERE 
    cpe.type_id = 'configurable' 
    AND cped.attribute_id = 77

But it got Syntax error near 'FROM catalog_product_entity AS cpe LEFT JOIN catalog_product_entit...' at line 5.

How I can fix this?

Thank you very much!

1
  • 1
    Your LEFT JOIN returns regular INNER JOIN result. If you want true LEFT JOIN result, move the cped.attribute_id condition from WHERE to ON. Commented Mar 27, 2022 at 19:29

1 Answer 1

1

UPDATE has no FROM clause, so you need to join the tables in the UPDATE clause

UPDATE catalog_product_entity_decimal cped
RIGHT JOIN catalog_product_entity AS cpe  ON cped.entity_id = cpe.entity_id
SET
    cped.value = NULL

WHERE 
    cpe.type_id = 'configurable' 
    AND cped.attribute_id = 77;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.