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 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2004-12-08 : 08:37:15
|
| I have a table called relations having these recordsId Description Pid1 x 02 z 03 a 24 b 25 c 16 n 17 p 48 r 39 s 210 t 6I want to write a query to get all the relations eg t's Pid is 6 which is id for n who has pid 1 which id for xSo the relation for t is t-n-xsimilarly p has p-b-zI used the following queryselect * from(Select R1.Description as "D5", "" as "D6" ,"" as "D7" from Relations R1 where R1.Pid=0 union Select R1.Description as "D5", R2.Description as "D6" ,"" as "D7" from Relations R1, Relations R2 where R1.Pid=R2.id and R2.Pid=0union Select r1.D3,t1.d1 , t1.D2 from(Select R1.Description as "D1", R2.Description as "D2" from Relations R1, Relations R2 where R1.Pid=R2.id) as t1,(Select R1.Description as "D3", R2.Description as "D4" from Relations R1, Relations R2 where R1.Pid=R2.id ) r1 where r1.d4=t1.d1 ) t order by len(d7) asc, len(d6) asc,d5which produced D5 D6 D7x z a z b z c x n x s z p b zr a zt n xBut its working for maximum of three relationsHow can I modify this query so that it will return the relations for any levelThanks in advanceMadhivanan |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2004-12-09 : 00:24:21
|
| Thank you for giving useful linksMadhivanan |
 |
|
|
|
|
|
|
|