Looking for some SQL which would list all SKU's with more than 1 product image attached to it.

Ideally I would also like to delete all images which are not used as base/small/thumbnail, but happy to do that that in the backend if that's easier.

The relevant tables seem to be catalog_product_entity_media_gallery, catalog_product_entity_media_gallery_value and catalog_product_entity_varchar.


The following SQL finds all images in catalog_product_entity_media_gallery which are not used as base/small/thumbnail:

FROM catalog_product_entity_media_gallery gal
  LEFT JOIN catalog_product_entity_varchar ent ON ent.value = gal.value
WHERE ent.value IS NULL;

Exported this as text file and then created a script which deleted all entries from:

  • catalog_product_entity_media_gallery
  • catalog_product_entity_media_gallery_value

where value_id was equal to the ones in the file generated above.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.