added to the model to maintain the depth of a node within a tree. In this model, finding the immediate children given a parent node can be accomplished with the following SQL code: 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.Depth = 1 -- Given Parent Node Left Index See also Tree traversal Tree (data structure) Adjacency list References External links Troels' links to Hierarchical data in RDBMSs Managing hierarchical data in relational databases PHP PEAR Implementation for Nested Sets – by Daniel Khan Transform any Adjacency List to Nested Sets using MySQL stored procedures PHP Doctrine DBAL implementation for Nested Sets – by PreviousNext R Nested Set – Nested Set example in R Database theory