How to Get Category Name by Category ID Using SQL in Magento 2
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
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> |
Done! Isn’t it simple?
If you have queries regarding the post, feel free to ask in the Comment section below.
I would like to solve your queries.
Also, do not forget to share this post with Magento Community via social media.
Thank you.
Related Post:
- How to Get Parent Category ID in Magento 2
- Solved: Error 1273 Unknown Collation utf8mb4_0900_ai_ci in MySQL
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
2 Comments
catalog_category_entity_varchar no longer have entity_id column
Hello Vishal,
We have checked in the latest Magento version 2.4.4 and entity_id column is there as well.
Thank You