MySQL Forums
Forum List  »  Newbie

find direct childs in a tree structure
Posted by: john mcclane
Date: August 13, 2005 10:34AM

Hi!
I've implemented a tree structure via the nested set modell.
now i need to find the direct childs of a vertex. So far i have found a query to get the indirect vertex, where v is the father, s any of its children and v2 a vertex in between. if v2 exists then s is the indirect child of v:

SELECT DISTINCT s.*
FROM kategorien AS s, kategorien AS v
INNER JOIN kategorien as v2
WHERE (v.id = 6) // knot i'm investigating
AND (s.id != v.id)
AND (s.links BETWEEN v.links AND v.rechts)
AND (v2.id != v.id) AND (v2.id != s.id) // v2 may not be either v or s

// specify how the vertex "in between" (v2) has to look like
AND (v2.links BETWEEN v.links AND v.rechts)
AND (v2.links BETWEEN v.links AND s.links)
AND (s.links BETWEEN v2.links AND v2.rechts)
ORDER BY s.id;

Unfortunately i need the direct ones. Since i use mysql 4.0something i cant use nested SELECT statements. And things like v2.id = NULL or v2.id is NULL dont work either.
i tried to get the difference set via s2.id NOT IN s.id, where s2 is any of v's children, but then i get just an empty set as a result.
someone has any idea?
thx
jmc

Options: ReplyQuote


Subject
Written By
Posted
find direct childs in a tree structure
August 13, 2005 10:34AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.