A title as catchy as a loose tablecloth. This will give you a list of all configurable products whose children have a particular attribute.
SELECT config_product.entity_id, prod_name.value AS product_name, config_product.sku FROM catalog_product_entity config_product JOIN eav_attribute ON eav_attribute.entity_type_id = 4 AND eav_attribute.attribute_code = "name" JOIN catalog_product_entity_varchar prod_name ON prod_name.`attribute_id` = eav_attribute.`attribute_id` AND prod_name.`entity_id` = config_product.`entity_id` WHERE config_product.entity_id IN ( SELECT parent_id FROM catalog_product_entity_int att_value JOIN `catalog_product_super_link` link ON link.product_id = att_value.entity_id AND att_value.`value` = attribute_value );
- As Magento only allows the creation of product links on dropdowns, catalog_product_entity_int should be fine to remain hardcoded.
- Change attribute_value to the option value id. An easy way to retrieve this from Magento’s admin is to look at the name of the input box when looking at the attribute’s Manage Label/Options tab; it will be something like “option[value]” where 959 is the option ID.
The SQL firstly uses a subquery to get all products which are being used as simples (if their product_id appears in the super_link table), and gets their configurable counterparts from this. We need to do this as a subquery their may be multiple configurables using the same simple product. It then uses the parent IDs in looking up more details from the catalog_product_entity and catalog_product_entity_varchar tables.