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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Leaf Nodes of trunk JOIN or ???

Author  Topic 

WAK
Starting Member

2 Posts

Posted - 2005-12-09 : 00:40:50
SQL Gurus please help.

I have following table:

+-------------+----------------------+--------+
| category_id | name | parent |
+-------------+----------------------+--------+
| 1 | ELECTRONICS | NULL |
| 2 | TELEVISIONS | 1 |
| 3 | TUBE | 2 |
| 4 | LCD | 2 |
| 5 | PLASMA | 2 |
| 6 | PORTABLE ELECTRONICS | 1 |
| 7 | MP3 PLAYERS | 6 |
| 8 | FLASH | 7 |
| 9 | CD PLAYERS | 6 |
| 10 | Single CD | 9 |
| 11 | 3 CD Changer | 9 |
| 12 | 5 CD Changer | 9 |
| 13 | 2 WAY RADIOS | 6 |
+-------------+----------------------+--------+


I want to retrieve the leaf nodes of a trunk from this data. I know to retrieve all the leaf nodes I can write a query i.e

SELECT t1.name FROM
category AS t1 LEFT JOIN category as t2
ON t1.category_id = t2.parent
WHERE t2.category_id IS NULL;


But I am interested to get the leaf nodes of a particular branch/trunk node e.g Portable Electronics

Thanks in advance. I hope prompt reply

WAK

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-12-09 : 01:28:40
Refer this
http://www.nigelrivett.net/RetrieveTreeHierarchy.html

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -