Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Set value to NULL from select query in SQL

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

How I can fix this?

Thank you very much!

>Solution :

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;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading