Hi everyone,
I have a table which holds folders, each folder having a folderid, foldername and parentid (null for the root nodes). Now I'd like to select all the children of a node, having only the folderid of the parent node. I have the following query, having the folderid 1 as a parameter:
SELECT folderid, foldername FROM tblfolder
WHERE parentid = 1 OR
parentid IN (SELECT folderid FROM tblfolder WHERE parentid = 1 OR parentid IN
(SELECT folderid FROM tblfolder WHERE parentid = 1 OR parentid IN (SELECT folderid FROM tblfolder WHERE parentid=1)))
and so on.
The problem is this only returns the children up to a given depth, what other way would you recommend to retrieve all the children of the node, no matter how deep the tree goes?
Thanks.
Jason
I have a table which holds folders, each folder having a folderid, foldername and parentid (null for the root nodes). Now I'd like to select all the children of a node, having only the folderid of the parent node. I have the following query, having the folderid 1 as a parameter:
SELECT folderid, foldername FROM tblfolder
WHERE parentid = 1 OR
parentid IN (SELECT folderid FROM tblfolder WHERE parentid = 1 OR parentid IN
(SELECT folderid FROM tblfolder WHERE parentid = 1 OR parentid IN (SELECT folderid FROM tblfolder WHERE parentid=1)))
and so on.
The problem is this only returns the children up to a given depth, what other way would you recommend to retrieve all the children of the node, no matter how deep the tree goes?
Thanks.
Jason