Magento – get category Ids from MySQL database

When doing imports of products to magento, you often have to set id of category, where each item belongs. Here is a simple SQL query, that will show you the category ids in a tree structure, so it is easy to find the appropriate category id.

SELECT ccev.entity_id AS categoryID, cce.path, ccev.value
FROM catalog_category_entity cce
JOIN catalog_category_entity_varchar ccev ON ( cce.entity_id = ccev.entity_id
AND ccev.attribute_id =31 )
GROUP BY ccev.entity_id
ORDER BY path
LIMIT 1000

The result than looks like this:

categoryID path value
1 1 Root Catalog
2 1/2 Default Category
12 1/2/12 Turistické průvodce
26 1/2/12/26 Česká republika
27 1/2/12/27 Zahraničí
13 1/2/13 Turistické mapy
28 1/2/13/28 Česká republika
29 1/2/13/29 Zahraničí
14 1/2/14 Cykloturistické průvodce
32 1/2/14/32 Česká republika
33 1/2/14/33 Zahraničí
15 1/2/15 Nástěnné mapy
36 1/2/15/36 Česká republika
37 1/2/15/37 Zahraničí
16 1/2/16 GPS navigace

Žádné příbuzné články.

This entry was posted in Webdesign. Bookmark the permalink. Follow any comments here with the RSS feed for this post. Trackbacks are closed, but you can post a comment.

One Comment

  1. jackie napsal:

    Hi
    Thanks, great sql, really helpful for Magento Imports to id the category id simply.

    I found it works if I take out line 4: AND ccev.attribute_id =31

    cheers

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>