{"id":2168,"date":"2022-11-03T07:30:15","date_gmt":"2022-11-03T07:30:15","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/sql-query-to-get-all-products-with-custom-options-in-magento-2\/"},"modified":"2025-10-03T12:55:39","modified_gmt":"2025-10-03T07:25:39","slug":"sql-query-to-get-all-products-with-custom-options-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/sql-query-to-get-all-products-with-custom-options-in-magento-2\/","title":{"rendered":"SQL Query to Get All Products With Custom Options in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Offering customization options is one of the most common ways to meet your customers&#8217; requirements and increase your sales.  <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">By default, <a title=\"Magento Commerce\" href=\"https:\/\/business.adobe.com\/products\/magento\/magento-commerce.html\" target=\"_blank\" rel=\"noopener\">Magento 2<\/a> offers the functionality of custom options to store owners that enables product customization up to a significant extent. It is highly useful for merchants selling products that come in different variants or need inputs from the customer&#8217;s end. Additionally, <a title=\"How to Use SQL Query for Case Sensitive Data in Magento 2\" href=\"https:\/\/meetanshi.com\/blog\/use-sql-query-for-case-sensitive-data-in-magento-2\/\">Use SQL Query for Case Sensitive Data in Magento 2<\/a> is vital, especially when dealing with database operations that require sensitivity to letter casing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/experienceleague.adobe.com\/en\/docs\/commerce-admin\/catalog\/products\/settings\/settings-advanced-custom-options\" target=\"_blank\" rel=\"noreferrer noopener\">Customizable options in Magento 2<\/a> can be added and configured for the products from the product edit section. You can find the different custom options and their values in the same section. But, what if you want to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Get the list of all products with custom options in Magento 2 using SQL?<\/li>\n\n\n\n<li>Find values of different custom options in Magento 2 using SQL?<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Earlier, we posted a complete method to <a title=\"Create custom options programmatically in Magento 2\" href=\"https:\/\/meetanshi.com\/blog\/create-custom-options-programmatically-in-magento-2\/\" target=\"_blank\" rel=\"noopener\">create custom options programmatically in Magento 2<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this Magento 2 solution post, I will share the <em><strong>SQL query to get all products with custom options in Magento 2<\/strong><\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s get started!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to Find All Products With Custom Options Using MySQL in Magento 2<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In order to get all the products with custom options in Magento 2 through SQL, we need run the following query:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT\n    *\nFROM\n    catalog_product_entity\nWHERE\n    type_id NOT LIKE 'configurable'\n    AND type_id NOT LIKE 'bundle'\n    AND has_options = 1;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The query returns a list of all the products that are neither configurable nor bundled, and have options enabled.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now, you have a list of all the products that have custom options enabled in your store.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Wanna dig deeper?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use the following SQL query to find custom options and their values of individual products in Magento 2:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT\n    e.sku,\n    cv.value AS product_name,\n    t.title AS custom_option_title,\n    GROUP_CONCAT(ot.title ORDER BY ov.sort_order SEPARATOR ', ') AS custom_option_values,\n    GROUP_CONCAT(price.price ORDER BY ov.sort_order SEPARATOR ', ') AS option_prices\nFROM\n    catalog_product_option o\nJOIN\n    catalog_product_entity e\n    ON e.entity_id = o.product_id\nJOIN\n    catalog_product_option_title t\n    ON t.option_id = o.option_id\nJOIN\n    (\n        SELECT\n            ea.attribute_id\n        FROM\n            eav_attribute ea\n        JOIN\n            eav_entity_type et\n            ON et.entity_type_id = ea.entity_type_id\n        WHERE\n            et.entity_type_code = 'catalog_product'\n            AND ea.attribute_code = 'name'\n    ) AS name_attribute\nJOIN\n    catalog_product_entity_varchar cv\n    ON cv.entity_id = e.entity_id\n    AND cv.attribute_id = name_attribute.attribute_id\nLEFT JOIN\n    catalog_product_option_type_value ov\n    ON ov.option_id = o.option_id\nLEFT JOIN\n    catalog_product_option_type_title ot\n    ON ot.option_type_id = ov.option_type_id\nLEFT JOIN\n    catalog_product_option_type_price price\n    ON price.option_type_id = ot.option_type_id\nGROUP BY\n    e.sku,\n    t.title,\n    cv.value\nORDER BY\n    e.sku,\n    t.title;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That&#8217;s it!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Run the above query and you will get all the custom options-enabled products in Magento 2 along with detailed information about the values of each of the options.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also, do not forget to share this helpful Magento 2 tutorial with your friends via social media.  <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thanks for reading!  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Offering customization options is one of the most common ways to meet your customers&#8217; requirements and increase your sales. By default, Magento 2 offers the&#8230;<\/p>\n","protected":false},"author":38,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-2168","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/2168","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/38"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=2168"}],"version-history":[{"count":5,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/2168\/revisions"}],"predecessor-version":[{"id":23071,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/2168\/revisions\/23071"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=2168"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=2168"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=2168"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}