Categories are extremely important to differentiate products in E-commerce stores. Whether it is small, medium or large-sized Magento 2 store, the categories help the store owner to separate products and services with category names.
After creating categories in Magento 2, while loading and debugging the category page, the Magento developers sometimes only get category ID in the URL. The category name should appear on the page.
Every category name contains a category ID. Manually finding bulk of the category names by category IDs from the backend is a time-consuming process.
Therefore, I have come up with a solution to get category name by category ID using SQL in Magento 2.
Programmatic Solution to Get Category Name by Category ID Using SQL in Magento 2
SELECT cce.entity_id as 'Category Id', ccev.value as 'Category Name' FROM `catalog_category_entity_varchar` ccev JOIN catalog_category_entity cce ON cce.entity_id = ccev.entity_id AND ccev.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_category' ) ) and cce.entity_id = < Your Category Id>
Replace <Your Category Id> with your category ID.
Done! Isn’t it simple?
Also, do not forget to share this post with Magento Community via social media.
Thank you.