SQL Category List – How to Get Full List of Categories Using SQL

categorysql

How would I format a SQL query to get a list of all categories (id, name, and url_path) from my Magento database?

Alternatively, if you know the tables I need to do this, a list and some sort of explanation as to what I need to do would be a great help.

Best Answer

Using @mpaepper answer I was able to get a query that seems to be pulling the correct information back. I was able to test it on two different magento databases and each looked right. Anyway here it is.

  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'; 

I probably didn't need to join eav_entity_type but I will probably be using this query again on different versions of magento so I think this will help keep the query reusable.

Related Topic