Academic, really, with Oracle 9i. (Which is what we're using at the day job.)

If 7 is the categoryid for "Hockey":

select categoryid, category, level
from catalog
start with categoryid=7
connect by parentid = prior categoryid

level is a pseudo-column indicates the level of the tree, starting with 1.

Throw in SYS_CONNECT_BY_PATH(category,'|') into the SELECT clause and
you can display the whole chain as well.


On 5/9/05, Kazmierczak, Kevin <[EMAIL PROTECTED]> wrote:
> How does everyone handle an N level parent-child type relationship
> within the same table?
> 
> Say you have the following table setup for Categories
> 
> categoryid
> 
> category
> 
> parentid
> 
> You could have any level of categories each with the parent pointing up
> the path.  The problem I'm interested in is how to retrieve data out of
> that setup.  Right now I am using a UDF that opens cursors up and scans
> the path to match records but that is killing the execution time as
> traffic builds up on the site.
> 
> Example:
> 
> Category Path: Sports -> Hockey -> Teams -> Buffalo Sabres
> 
> You want to find anything that is a member of the hockey category and
> any sub category within.
> 
> One option I am considering is to write out the entire path or write out
> all the categories in a table or something that would make retrieval
> faster, but would make an administrative nightmare.
> 
> What do you recommend?
> 
> Thanks.
> 
> -----------------------------------------------
> Kevin Kazmierczak
> Senior Software Developer
> Citynet
> 113 Platinum Drive
> Bridgeport, WV 26330
> Phone: 304.848.5451
> http://www.citynet.net
> 
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking 
application. Start tracking and documenting hours spent on a project or with a 
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:206102
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to