Skip to main content Link Search Menu Expand Document (external link)

Coding Tips

Joomla

Querying for a category and all it’s subcategories

Joomla nests tables using a parent_id column and lft/rgt columns to maintain the hierarchy. Here is a simple query to retrieve the category <CategoryId> and all it descendent categories.

SELECT tree.*
FROM #__categories AS tree, #__categories AS parent 
WHERE tree.lft BETWEEN parent.lft AND parent.rgt AND parent.id = <CategoryId>;

Copyright © 2020-2022 Joomlashack. License GPL