AI Reports

Magento 2 SQL queries › Products and catalogue

Which enabled products aren't in any category?

Short answer: The product grid can't filter by category. Look for enabled, visible products with no row in catalog_category_product.

In the Magento admin

  1. Open each category in Catalog › Categories and check Products in Category. On a big catalogue that isn't practical.

With one query

These queries only read data. Run them on a copy of your database if you can, or ask your developer to. If your tables have a prefix (set in app/etc/env.php), add it to each table name.

Magento Open Source

SELECT e.sku, e.type_id AS type
FROM catalog_product_entity e
JOIN eav_entity_type t ON t.entity_type_code = 'catalog_product'
JOIN eav_attribute a_status     ON a_status.entity_type_id     = t.entity_type_id AND a_status.attribute_code     = 'status'
JOIN eav_attribute a_visibility ON a_visibility.entity_type_id = t.entity_type_id AND a_visibility.attribute_code = 'visibility'
JOIN catalog_product_entity_int st  ON st.entity_id  = e.entity_id AND st.attribute_id  = a_status.attribute_id     AND st.store_id  = 0 AND st.value = 1
JOIN catalog_product_entity_int vis ON vis.entity_id = e.entity_id AND vis.attribute_id = a_visibility.attribute_id AND vis.store_id = 0 AND vis.value IN (2, 4)
WHERE NOT EXISTS (SELECT 1 FROM catalog_category_product cp WHERE cp.product_id = e.entity_id)
ORDER BY e.sku;

Adobe Commerce

Product, category, rule and CMS values are stored per version and joined on row_id (why):

SELECT e.sku, e.type_id AS type
FROM catalog_product_entity e
JOIN eav_entity_type t ON t.entity_type_code = 'catalog_product'
JOIN eav_attribute a_status     ON a_status.entity_type_id     = t.entity_type_id AND a_status.attribute_code     = 'status'
JOIN eav_attribute a_visibility ON a_visibility.entity_type_id = t.entity_type_id AND a_visibility.attribute_code = 'visibility'
JOIN catalog_product_entity_int st  ON st.row_id  = e.row_id AND st.attribute_id  = a_status.attribute_id     AND st.store_id  = 0 AND st.value = 1
JOIN catalog_product_entity_int vis ON vis.row_id = e.row_id AND vis.attribute_id = a_visibility.attribute_id AND vis.store_id = 0 AND vis.value IN (2, 4)
WHERE NOT EXISTS (SELECT 1 FROM catalog_category_product cp WHERE cp.product_id = e.entity_id)
  AND e.created_in <= UNIX_TIMESTAMP() AND e.updated_in > UNIX_TIMESTAMP()
ORDER BY e.sku;

Good to know

Related

Gaurav Harsh

Gaurav Harsh is a Magento developer who works on large Adobe Commerce stores and builds AI Reports, a Magento extension for asking your store's data questions in plain English. LinkedIn