Magento1 Attributes – Delete Unused Attribute Values

attributeseavimport

I am using the fastsimpleimport module to create my custom import. This has a setDropdownAttributes() function to automatically create needed attribute values but it does not remove unused values. Those still show up in my advanced search.

How can I search and remove unused attribute values?

I think they are stored in eav_attribute_option_value but I am not sure how to check if they are used by a product.

Best Answer

delete c,b
from eav_attribute a
inner join eav_attribute_option b on a.attribute_id = b.attribute_id
inner join eav_attribute_option_value c on c.`option_id` = b.option_id
LEFT join catalog_product_entity_int pi on b.option_id=pi.value and pi.store_id=0 and b.attribute_id=pi.attribute_id
where entity_id is null

Try this Query..