O'Reilly logo

Joe Celko's Trees and Hierarchies in SQL for Smarties, 2nd Edition by Joe Celko

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 4. Nested Sets Model of Hierarchies
Trees are often drawn as “boxes-and-arrows” charts and that graphic tends to lock your mental image of a tree into a graph structure. Another way of representing trees is to show them as nested sets. It is strange that this approach was overlooked for so long among SQL programmers. Many of us are old enough to have used The Art of Computer Programming (Donald Knuth, ISBN 978-0321751041) in college as our textbook and we should remember this representation of trees in a chapter of his book. Younger programmers think of it as “counting tags” in XML, HTML, and other mark-up languages. Mathematical programmers can think of it as parentheses or as, well, nested sets.
Keywords: trees, subtrees, node, root, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required