Is there a simple way to query the children of a node?

前端 未结 6 1030
余生分开走
余生分开走 2020-12-10 05:19

I\'ve been using the crap out of the Nested Set Model lately. I have enjoyed designing queries for just about every useful operation and view. One thing I\'m stuck on is how

6条回答
  •  一生所求
    2020-12-10 06:16

    I'd go with a depth column, too. But use

    SELECT Child.Node, Child.LEFT, Child.RIGHT
    FROM Tree AS Child, Tree AS Parent
    WHERE
            Child.Depth = Parent.Depth + 1
            AND Child.LEFT > Parent.LEFT
            AND Child.RIGHT < Parent.RIGHT
            AND Parent.LEFT = 1  -- Given Parent Node Left Index
    

    Wikipedia

提交回复
热议问题