Magento 2 SQL queries › Products and catalogue
Which configurable products have no variant in stock?
Short answer: A configurable product is sellable only through its variants. Find parents where no linked child is in stock.
In the Magento admin
- Open each configurable product and check the Configurations grid for quantity and status.
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
FROM catalog_product_entity e
WHERE e.type_id = 'configurable'
AND NOT EXISTS (
SELECT 1
FROM catalog_product_super_link l
JOIN cataloginventory_stock_item si ON si.product_id = l.product_id
WHERE l.parent_id = e.entity_id AND si.is_in_stock = 1 AND si.qty > 0
)
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
FROM catalog_product_entity e
WHERE e.type_id = 'configurable'
AND e.created_in <= UNIX_TIMESTAMP() AND e.updated_in > UNIX_TIMESTAMP()
AND NOT EXISTS (
SELECT 1
FROM catalog_product_super_link l
JOIN cataloginventory_stock_item si ON si.product_id = l.product_id
WHERE l.parent_id = e.row_id AND si.is_in_stock = 1 AND si.qty > 0
)
ORDER BY e.sku;
Good to know
- On Adobe Commerce,
catalog_product_super_link.parent_idpoints to the parent'srow_id, whileproduct_idpoints to the child'sentity_id. Joining the parent onentity_idsilently returns the wrong products. - This uses the default stock. With multi-source inventory, check
inventory_source_itemby SKU as well.