0

Create an SQL script to find a simple product name with its configurable product SKU In Magento 2 [Magento 2]

Anyone with a better solution than my one are appreciated.

Please share your answer.

2 Answers 2

1

Query as follows:

select
 nametable.value as product_name,
 parent.type_id as parent_product_type, parent.sku as parent_sk,
 child.type_id as child_product_type, child.sku child_sku
from catalog_product_entity as parent
join catalog_product_relation as link
    on link.parent_id = parent.entity_id
join catalog_product_entity as child
    on child.entity_id = link.child_id
join catalog_product_entity_varchar as nametable ON nametable.row_id = parent.entity_id
AND nametable.store_id = 0
AND nametable.attribute_id = (SELECT attribute_id
  FROM eav_attribute
  WHERE attribute_code = 'name'
    AND entity_type_id =
      (SELECT entity_type_id
       FROM eav_entity_type
       WHERE entity_type_code = 'catalog_product'))
where parent.sku = 'product-sku'

If my answer helped you, you can accept the answer so it can help others also.

4
  • Sorry but this answer accepts only asking answer.. Commented Apr 2, 2020 at 17:39
  • @MohitPatel can you post a more optimize solution if possible? Commented Apr 3, 2020 at 4:57
  • you means one answer ?? Commented Apr 3, 2020 at 4:59
  • @MohitPatel optimize answer for Magento Enterprise Edition [2.3.3] Commented Apr 3, 2020 at 5:11
0

Optimized for Magento Commerce 2.3.3 ( formerly Enterprise Edition) - The parent uses row_id instead of entity_id. Also, removed store_id as it's unnecessary if you have one store and potentially wrong if you have multi store.

SELECT
  nametable.value child_name,
  parent.type_id parent_product_type,
  parent.sku parent_sku,
  child.type_id child_product_type,
  child.sku child_sku
FROM
  catalog_product_entity parent
  JOIN catalog_product_relation link
    ON link.parent_id = parent.row_id
  JOIN catalog_product_entity child
    ON child.entity_id = link.child_id
  JOIN catalog_product_entity_varchar nametable
    ON nametable.row_id = parent.row_id
    AND nametable.attribute_id =
    (SELECT
      attribute_id
    FROM
      eav_attribute
    WHERE attribute_code = 'name'
      AND entity_type_id =
      (SELECT
        entity_type_id
      FROM
        eav_entity_type
      WHERE entity_type_code = 'catalog_product'))
WHERE parent.sku = 'YOUR-SKU';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.