cancel
Showing results for 
Search instead for 
Did you mean: 

How to do recursive SQL query to get the path information

Former Member
0 Kudos

In our newest development in NWDS, we want to implement a function to list all parent nodes as a path.

The data schema(pathinfo) is like this:


ID            Name               Parent
=========================================
1              A                  null
2              B                   1
3              C                   2
4              D                   2

By following the Parent attribute and ID, we can get the path information for the current node.

E.g. for D, the parent is B(2), and the parent of B is A(1)

Therefore, the parent path of D is B_A

My question is, how to use SQL to list the parent path information for a specific node ID?

Do it naively, I need to execute the query "SELECT Parent FROM pathinfo where ID = X " recursively, each time get only one parent node. Is that the only way to solve this problem? If so, can we modify the data schema so that it can retrieves the parent path more efficiently?

Edited by: Zenghuan Shan on Feb 29, 2008 10:57 AM

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member751941
Active Contributor
0 Kudos

Hi Zenghuan ,

Check this thread

String query = "SELECT Parent FROM pathinfo where ID = "+ wdContext.currentPathinfoElement().getID();

ResultSet rs = stmt.executeQuery(query);

Regards,

Mithu