I recently did a migration from M1 to M2, and with doing that, all images came along. Some products tend to have north of 10 images, and some more like 1-3.

I am trying to find a simple and fast way of getting a list of products that would say for example have more than 5 images in their image collection. I don't need to view the images or see what the simple/base/thumbnail are. I just want the total count per product.

Is there a simple SQL query or php block I could run for this?


The following query returns the number of images per product:

SELECT sku,count(*) FROM `catalog_product_entity` AS a 
LEFT JOIN `catalog_product_entity_media_gallery_value_to_entity` AS b ON a.entity_id = b.entity_id 
group by sku

I am not sure if it works properly in case of complex products or bundle. But it gives you an idea about how to proceed.

More generally, you should use the following Magento tables:

  • catalog_product_entity (for product ids)
  • catalog_product_entity_media_gallery_value_to_entity (for image and product relationship)
  • catalog_product_entity_media_gallery (for images path)

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.