🔥 Just Launched! Werra Premium Template for HyväSee it in Action

How to Get Category Name by Category ID Using SQL in Magento 2

By Sanjay JethvaUpdated on May 21, 2025 1 min read

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.

Sanjay Jethva Full Image
Article bySanjay 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.