Skip to content

Instantly share code, notes, and snippets.

@czterystaczwarty
Last active October 13, 2015 01:28
Show Gist options
  • Save czterystaczwarty/4117714 to your computer and use it in GitHub Desktop.
Save czterystaczwarty/4117714 to your computer and use it in GitHub Desktop.
Update with subselect on the same table.
UPDATE
   product
SET
   product_active = 0, product_date_deleted = NOW()
WHERE product_id IN (SELECT product_id
   FROM (SELECT
         product.product_id
       FROM
           product
       LEFT JOIN
           product_image ON (product.product_id = product_image.product_id AND product.product_date_deleted IS NULL)
       GROUP BY
           product.product_id
       HAVING
           COUNT(product_image.image_id) = 0) product_copy );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment