AI Reports

Magento 2 SQL queries › Store setup

Which root category does each store use?

Short answer: Each store (store group) has one root category. The query lists them with their names.

In the Magento admin

  1. Go to Stores › All Stores and open each store; the Root Category is on its page.

With one query

These queries only read data. Run them on a copy of your database if you can, or ask your developer to. If your tables have a prefix (set in app/etc/env.php), add it to each table name.

Magento Open Source

SELECT w.name AS website, g.name AS store, g.root_category_id, nm.value AS root_category
FROM store_group g
JOIN store_website w ON w.website_id = g.website_id
JOIN catalog_category_entity c ON c.entity_id = g.root_category_id
JOIN eav_entity_type t ON t.entity_type_code = 'catalog_category'
JOIN eav_attribute a_name ON a_name.entity_type_id = t.entity_type_id AND a_name.attribute_code = 'name'
LEFT JOIN catalog_category_entity_varchar nm ON nm.entity_id = c.entity_id AND nm.attribute_id = a_name.attribute_id AND nm.store_id = 0
WHERE g.group_id > 0
ORDER BY w.website_id, g.group_id;

Adobe Commerce

Product, category, rule and CMS values are stored per version and joined on row_id (why):

SELECT w.name AS website, g.name AS store, g.root_category_id, nm.value AS root_category
FROM store_group g
JOIN store_website w ON w.website_id = g.website_id
JOIN catalog_category_entity c ON c.entity_id = g.root_category_id
JOIN eav_entity_type t ON t.entity_type_code = 'catalog_category'
JOIN eav_attribute a_name ON a_name.entity_type_id = t.entity_type_id AND a_name.attribute_code = 'name'
LEFT JOIN catalog_category_entity_varchar nm ON nm.row_id = c.row_id AND nm.attribute_id = a_name.attribute_id AND nm.store_id = 0
WHERE g.group_id > 0
  AND c.created_in <= UNIX_TIMESTAMP() AND c.updated_in > UNIX_TIMESTAMP()
ORDER BY w.website_id, g.group_id;

Good to know

Related

Gaurav Harsh

Gaurav Harsh is a Magento developer who works on large Adobe Commerce stores and builds AI Reports, a Magento extension for asking your store's data questions in plain English. LinkedIn