Skip to content

Instantly share code, notes, and snippets.

@tegansnyder
Created January 16, 2014 21:58
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save tegansnyder/8464261 to your computer and use it in GitHub Desktop.
Save tegansnyder/8464261 to your computer and use it in GitHub Desktop.
Magento - finding products without images. Raw SQL.
SELECT *
FROM `catalog_product_entity` AS a
LEFT JOIN `catalog_product_entity_media_gallery` AS b ON a.entity_id = b.entity_id
WHERE b.value IS NULL
@WinstonN
Copy link

WinstonN commented Aug 7, 2019

Hello my friends - I hope you are all doing well
Here is my code I used in Magento 2, perhaps it will help you <3

SELECT e.entity_id AS 'id',
       e.sku AS 'sku',
       v2.value AS 'image',
       v3.value AS 'thumbnail',
       v4.value AS 'small image',
       mg.value AS 'media_gallery'
FROM catalog_product_entity e
LEFT JOIN catalog_product_entity_varchar v2 ON e.entity_id = v2.row_id
AND v2.store_id = 0
AND v2.attribute_id =
  (SELECT attribute_id
   FROM eav_attribute
   WHERE attribute_code = 'image'
     AND entity_type_id =
       (SELECT entity_type_id
        FROM eav_entity_type
        WHERE entity_type_code = 'catalog_product'))
LEFT JOIN catalog_product_entity_varchar v3 ON e.entity_id = v3.row_id
AND v3.store_id = 0
AND v3.attribute_id =
  (SELECT attribute_id
   FROM eav_attribute
   WHERE attribute_code = 'thumbnail'
     AND entity_type_id =
       (SELECT entity_type_id
        FROM eav_entity_type
        WHERE entity_type_code = 'catalog_product'))
LEFT JOIN catalog_product_entity_varchar v4 ON e.entity_id = v4.row_id
AND v4.store_id = 0
AND v4.attribute_id =
  (SELECT attribute_id
   FROM eav_attribute
   WHERE attribute_code = 'small_image'
     AND entity_type_id =
       (SELECT entity_type_id
        FROM eav_entity_type
        WHERE entity_type_code = 'catalog_product'))
LEFT JOIN
  (SELECT m1.value_id AS m1_value_id, GROUP_CONCAT(m2.value) AS VALUE, m2.value_id AS m2_value_id, m1.row_id AS m1_row_id
   FROM catalog_product_entity_media_gallery_value m1
   INNER JOIN catalog_product_entity_media_gallery m2 ON m2.value_id = m1.value_id
   AND m2.attribute_id =
     (SELECT attribute_id
      FROM eav_attribute
      WHERE attribute_code = 'media_gallery'
        AND entity_type_id =
          (SELECT entity_type_id
           FROM eav_entity_type
           WHERE entity_type_code = 'catalog_product'))
   GROUP BY m1.row_id) mg ON e.entity_id = m1_row_id
WHERE e.sku IN
(
"sku1",
"sku2",
"sku3"
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment