Hi there, hope someone can help

I have a standard hirechal database of categories and links.

However, I also have permissions to view certain categories. I have a table like this:

| usergroup | categoryid

so for a user of usergroup X they need an entry in the user_cat table to see the category.

Now, the problem is that the category table is:

| id | name | linkcount

What I want to do is be able to do queries linking this all together; so that I can show a user how many articles are in the categories they want to view, but a parent should include its childrens counts.

At the moment the only way I can think of doing this without recursive queries is to get all the category data into PHP and do it that way, very ugly.

Any ideas?