{"id":1485,"date":"2021-01-04T11:04:20","date_gmt":"2021-01-04T11:04:20","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/get-category-name-by-category-id-using-sql-magento-2\/"},"modified":"2025-05-21T17:17:38","modified_gmt":"2025-05-21T11:47:38","slug":"get-category-name-by-category-id-using-sql-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/get-category-name-by-category-id-using-sql-magento-2\/","title":{"rendered":"How to Get Category Name by Category ID Using SQL in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/create-new-root-category-in-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">creating categories in Magento 2<\/a>, 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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Therefore, I have come up with a solution to&nbsp;<strong>get category name by category ID using SQL in Magento 2<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Programmatic Solution to Get Category Name by Category ID Using SQL in Magento 2<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT cce.entity_id as 'Category Id',\n       ccev.value    as 'Category Name'\nFROM `catalog_category_entity_varchar` ccev\n         JOIN\n     catalog_category_entity cce\n     ON cce.entity_id = ccev.entity_id\n         AND ccev.attribute_id =\n             (\n                 SELECT attribute_id\n                 FROM eav_attribute\n                 WHERE attribute_code = 'name'\n                   and entity_type_id =\n                       (\n                           SELECT entity_type_id\n                           FROM eav_entity_type\n                           WHERE entity_type_code = 'catalog_category'\n                       )\n             ) and cce.entity_id = &lt; Your Category Id><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Replace<strong>&nbsp;&lt;Your Category Id&gt;<\/strong>&nbsp;with your category ID.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Done! Isn\u2019t it simple?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also, do not forget to share this post with Magento Community via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-1485","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1485","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=1485"}],"version-history":[{"count":2,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1485\/revisions"}],"predecessor-version":[{"id":13887,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1485\/revisions\/13887"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1485"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1485"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1485"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}