Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 Other Topics
 Recursive SQL Query for a category table

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-01-31 : 09:41:42
Dave writes "Hi,

This seems like a really great service you offer. Would just like to say thanks in advance. Hopefully this question makes it on your list to answer.

I have created a Oracle8i database everything works fine BUT, we would like to refine a certain point.

We HAD a category (tbcategory) table and a subcategory (tbsubcategory) table. After further discussion there is a need to have more than 1 subcategory, possible 2,3 or 4. Instead of making 3,4,5 sub-subs-sub category tables I have come up with this.

Some sample data below just for clarification.

TBCATEGORY

CatID (num), ParentID (num), CatDesc (vchar2)

1, NULL, Automotive --------> Main category
2, 1, Dealership --------> Sub-category
3, 2, New Car Dealer --------> Sub-sub-category
4, 2, Used Car Dealer --------> Sub-sub-category
.
.
.

Now this table is related to a message table (tbmessages) and tbmessages has a CatID (FK of tbcategory) to identify what category/sub/sub-sub(if applicable) it belongs to.

Hopefully this is clear so far, my problem is how to determine the total number of messages for a parent dir (counting all the subcategories and sub-sub-categories)

i.e. - Automotive (999 messages)

I know there must be an answer to this, maybe I am just looking too closely. I would appreciate any help from you Mr. Guru or anybody reading this!"
   

- Advertisement -