Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Need SQL for tree structure
Message
From
28/08/2000 07:24:31
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Need SQL for tree structure
Miscellaneous
Thread ID:
00409722
Message ID:
00409722
Views:
46
Hi All,

MyTable with 3 fields in it viz. code, name, group and has a primary key on code.

group can be blank or have another code and can have a nested level. If it is 0 then it is top level group or it belongs to another top level group.

for example: following data is available
Code	Name	Group
1	XYZ	0
2	ABC	0
3	XXX	1
4	XXY	0
5	XAB	1
6	XAA	2
7	AAA	0
8	AXB	0
9	AYY	4
10	ABA	2
11	AWS	6
12	AWD	6
What I want was to have the above sorted through a SQL query and the output should be like this:
Code	Name	Group
1	XYZ	0
3	XXX	1
5	XAB	1
2	ABC	0
6	XAA	2
11	AWS	6
12	AWD	6
10	ABA	2
4	XXY	0
9	AYY	4
7	AAA	0
8	AXB	0
If you analyse the above output it is something like
	1
		3
		5
	2
		6
			11
			12
		10
	4
		9
	7
	8
Can it be possible with a SQL query?

Thanks in advance.
Reply
Map
View

Click here to load this message in the networking platform