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.
| Author |
Topic |
|
james_b
Starting Member
9 Posts |
Posted - 2004-08-04 : 12:42:27
|
| Hi - I'm having a problem writing the sql to do a join between a hierarchical table and a link table, for example:Zone Table***********Zone_ID Zone_Name1 | UK2 | Yorkshire3 | Buckinghamshire4 | London5 | Manchester6 | USA7 | Washington8 | Florida9 | IdahoZone_Hierarchy Table********************Zone_ID Subzone_ID1 | 21 | 31 | 41 | 56 | 76 | 86 | 9How would I go about writing a sql statement that retrieves the data like this:Parent_Zone_Id Parent_Zone Subzone_Id Subzone1 UK 2 Yorkshire1 UK 3 Buckinghamshire1 UK 4 London1 UK 5 Manchester1 USA 7 Washington1 USA 8 Florida1 USA 9 IdahoHope this makes it clear - thanks for any help :)James |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2004-08-04 : 12:59:28
|
| Select Parent_Zone_Id = pZ.zone_Id,Parent_Zone = pZ.zone_Name,Subzone_Id = cZ.zone_Id,Subzone = cZ.zone_NameFrom zone_Hierarchy as zHInner Join zone as pZOn zH.zone_Id = pZ.zone_IdInner Join zone as cZOn zH.subzone_Id = cZ.zone_IdCorey |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2004-08-04 : 16:20:48
|
| You should normalize your data....Brett8-) |
 |
|
|
james_b
Starting Member
9 Posts |
Posted - 2004-08-05 : 04:10:12
|
| Seventhnight - works great - thanks :)X002548 - why does it need normalizing? Surely it's just hierarchical? |
 |
|
|
|
|
|