Here is a query that will return a list of categories that have active products and 4 levels above that those categories are subs to - how you choose to use it is your business. In other words, if you use it to delete categories that you later find should not have been, I am not responsible.
At this stage it only handles 5 levels - but it could go farther if needed. I have tested this in MySQL and it tolerates the nested sub-selects. Using an ODBC connection I found that MS Access does not.
Code:
SELECT categories_id FROM zen_products_to_categories
WHERE products_id IN (SELECT products_id FROM zen_products WHERE products_status = 1)
UNION
SELECT zen_categories.parent_id FROM zen_categories
WHERE zen_categories.categories_id In (SELECT categories_id FROM zen_products_to_categories)
UNION
SELECT parent_id FROM zen_categories
WHERE categories_id IN( SELECT zen_categories.parent_id FROM zen_categories WHERE zen_categories.categories_id In (SELECT categories_id FROM zen_products_to_categories))
UNION
SELECT parent_id FROM zen_categories
WHERE categories_id IN (SELECT parent_id FROM zen_categories
WHERE categories_id IN( SELECT zen_categories.parent_id FROM zen_categories WHERE zen_categories.categories_id In (SELECT categories_id FROM zen_products_to_categories)))
UNION
SELECT parent_id FROM zen_categories
WHERE categories_id IN (
SELECT parent_id FROM zen_categories
WHERE categories_id IN (SELECT parent_id FROM zen_categories
WHERE categories_id IN( SELECT zen_categories.parent_id FROM zen_categories WHERE zen_categories.categories_id In (SELECT categories_id FROM zen_products_to_categories))))
ORDER BY categories_id
Good luck and ALWAYS backup your database!