You are here: How do I write a query to get the path from ancestor to node in a tree? « MsSQL Server « IT news, forums, messages
How do I write a query to get the path from ancestor to node in a tree?

Posted by Tzvika Barenholz on 10/21/44 11:26

Hi all. Here's my problem: I have a tree linking macaddresses (bigints)
in a tree structure. i want to get the path from node a to b.



create table tree1(father bigint , child bigint);

insert into tree1 (father,child) values (100,200);
insert into tree1 (father,child) values (100,300);
insert into tree1 (father,child) values (100,400);
insert into tree1 (father,child) values (200,2000);
insert into tree1 (father,child) values (200,3000);
insert into tree1 (father,child) values (100,4000);
insert into tree1 (father,child) values (2000,11111);

you can see that 100 --> 200 --> 2000 --> 11111

select * from tree1
what i would like is a query that given two parameters returns the path
between
them, in the case of 100,11111 i want to get
100
200
2000
11111

if possible as different rows, but columns will do to.

of course i do not know the legnth of the path. it can be very big

thx in advance
Tzvika

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация