Improved the query slightly so I can now also limit by depth...
Code:
SELECT node.name, node.category_id, node.lft, node.rgt, node.parent_id, (COUNT(parent.category_id) - (sub_tree.depth + 1)) AS depth
FROM millnedev.ips_classifieds_categories AS node,
millnedev.ips_classifieds_categories AS parent,
millnedev.ips_classifieds_categories AS sub_parent,
(
SELECT node.category_id, (COUNT(parent.category_id) - 1) AS depth
FROM millnedev.ips_classifieds_categories AS node,
millnedev.ips_classifieds_categories AS parent
WHERE node.lft BETWEEN parent.lft AND parent.rgt
AND node.category_id = '1'
GROUP BY node.category_id
ORDER BY node.lft
) AS sub_tree
WHERE node.lft BETWEEN parent.lft AND parent.rgt
AND node.lft BETWEEN sub_parent.lft AND sub_parent.rgt
AND sub_parent.category_id = sub_tree.category_id
GROUP BY node.category_id
HAVING depth BETWEEN 1 AND 2
ORDER BY node.lft;
But now need to work out how to factor back in the join to get the item count also.
Bookmarks