CHAPTER 6 The Linear Version of the Nested Sets Model

IF YOU LOOK at the diagram that shows the left and right numbers on a number line, you will realize that this diagram can be used directly to represent a tree in a nested sets model. The left and right (lft, rgt) numbers each appear once, but the nodes of the tree appear exactly twice—once with the lft number and once with the rgt number. The table can be defined like this:

image

In fairness the “got_all_numbers” and “exactly_twice” constraints will be hard to implement in most SQL products today, but they are legal in full SQL-92. Our OrgChart tree is represented by this data.

OrgChart

The standard ...

Get Joe Celko's Trees and Hierarchies in SQL for Smarties now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.