Skip to content

Instantly share code, notes, and snippets.

@kesonno
Created January 27, 2015 17:06
Show Gist options
  • Save kesonno/be8ecda2633349f1dfa9 to your computer and use it in GitHub Desktop.
Save kesonno/be8ecda2633349f1dfa9 to your computer and use it in GitHub Desktop.
Get actually used options list for a given attribute in a given website
SELECT DISTINCT o.option_id, v.value
FROM `eav_attribute` a
INNER JOIN `eav_attribute_option` o ON a.`attribute_id` = o.`attribute_id`
INNER JOIN `eav_attribute_option_value` v ON v.`option_id` = o.`option_id`
INNER JOIN `eav_entity_type` t ON t.`entity_type_id` = a.`entity_type_id`
INNER JOIN `catalog_product_entity_int` pi ON o.`option_id` = pi.`value` AND o.`attribute_id` = pi.`attribute_id`
INNER JOIN `catalog_product_website` pw ON pw.product_id = pi.entity_id
WHERE pi.`entity_id` IS NOT NULL
AND a.attribute_code = '<attribute code>'
AND t.`entity_type_code` = "catalog_product"
AND pw.`website_id` = <website id>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment