Magento 2 – How to Get Category List with ID from Database

databasemagento2

I want to query the all product categories name and id from the magento 2.1 database. I found the sql query but it showing the error.

unknown column entity_type_id in catalog_category_entity

SQL Query

 SELECT DISTINCT cc.entity_id as id, cc.value as path, cc1.value as name    
  FROM catalog_category_entity_varchar cc    
  JOIN catalog_category_entity_varchar cc1 ON cc.entity_id=cc1.entity_id    
  JOIN eav_entity_type ee ON cc.entity_type_id=ee.entity_type_id
  JOIN catalog_category_entity cce ON cc.entity_id=cce.entity_id
  WHERE cc.attribute_id = '57' AND cc1.attribute_id = '41' AND ee.entity_model = 'catalog/category';

Best Answer

Try this:

SELECT DISTINCT cc.entity_id as id, cc.value as path, cc1.value as name    
FROM 
    catalog_category_entity_varchar cc    
    JOIN catalog_category_entity_varchar cc1 ON cc.entity_id=cc1.entity_id    
    JOIN catalog_category_entity cce ON cc.entity_id=cce.entity_id
 WHERE 
    cc.attribute_id = '57' AND 
    cc1.attribute_id = '41' ; 
Related Topic