Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 17th, 2007, 10:21 AM
Registered User
 
Join Date: Mar 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to LiamLiamLiam Send a message via MSN to LiamLiamLiam
Default Multiple Self Join w/Dynamic Level Hierarchy

I'm trying to wrap my head around these multiple self joins with my "Areas" table. The table is structured as so:

Table Name: Areas
----------------------------------------------------
| ID | Area | Parent | Order |
----------------------------------------------------
| 1 | Executive | 0 | 1 |
| 2 | Finance | 1 | 1 |
| 3 | Security | 1 | 3 |
| 4 | Records Management | 1 | 2 |
| 5 | Financial Operations | 2 | 1 |
| 6 | Financial Policy | 2 | 2 |
| 7 | Team A | 5 | 1 |
| 8 | Team B | 5 | 2 |
----------------------------------------------------

Here the hierarchy has 4 levels, but that could change at any time if another area was added to "Team B". Is there a way to query this table to bring back a column for each level in the hierarchy, with the master parent beginning on the left and the last child on the far right. Something like this:

--------------------------------------------------------------------------
| Col 1 | Col 2 | Col 3 | Col 4 |
--------------------------------------------------------------------------
| Executive | NULL | NULL | NULL |
| Executive | Finance | NULL | NULL |
| Executive | Finance | Financial Operations | NULL |
| Executive | Finance | Financial Operations | Team A |
| Executive | Finance | Financial Operations | Team B |
| Executive | Records Management | NULL | NULL |
| Executive | Security | NULL | NULL |
--------------------------------------------------------------------------

Is this possible? Or would you need to know the depth of the hierarchy to write out each join?

Also what would be the most effective way to query this with joins?






Similar Threads
Thread Thread Starter Forum Replies Last Post
Two Level Dynamic DropDown Question workib ASP.NET 3.5 Basics 6 May 14th, 2008 09:18 PM
Two Level Dynamic DropDown List Error Question workib BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 May 3rd, 2008 02:37 AM
Grouping in XSLT at same level of hierarchy... concen XSLT 2 April 6th, 2006 10:12 AM
multiple self-join boson SQL Language 2 April 23rd, 2004 05:20 AM
Inner Join multiple tables qwprince Classic ASP Databases 5 July 23rd, 2003 02:33 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.