Joe Celko's Trees and Hierarchies in SQL for Smarties

2nd Edition

Authors: Joe Celko
Paperback ISBN: 9780123877338
eBook ISBN: 9780123877567
Imprint: Morgan Kaufmann
Published Date: 20th January 2012
Page Count: 296
Tax/VAT will be calculated at check-out
Compatible Not compatible
VitalSource PC, Mac, iPhone & iPad Amazon Kindle eReader
ePub & PDF Apple & PC desktop. Mobile devices (Apple & Android) Amazon Kindle eReader
Mobi Amazon Kindle eReader Anything else

Institutional Access

Table of Contents

Chapter 1 Graphs, Trees and Hierarchies

1.1 Basic Graph Theory

1.1.1 Terminology

1.1.2 Edges versus Nodes

1.1.3 Directed versus Undirected Graphs

1.2 Tree versus Hierarchies

1.2.1 Trees

1.2.2 Types of Trees

1.2.3 Hierarchies

1.2.4 Types of Hierarchies

Chapter 2 Adjacency List Model

2.1 The Simple Adjacency List Model

2.2 The Simple Adjacency List Model is not normalized.

2.2.1 UPDATE Anomalies

2.2.2 INSERT Anomalies

2.2.3 DELETE Anomalies

2.2.4 Structural Anomalies

2.3 Fixing the Adjacency List Model

2.3.1 Concerning the Use of NULLs

2.4 Navigation in Adjacency List Model

2.4.1 Cursors and Procedural Code

2.4.2 Self-joins

2.4. 3 Recursive CTEs

2.5 Inserting Nodes in the Adjacency List Model

2.6 Deleting Nodes in the Adjacency List Model

2.6.1 Deleting an Entire Subtree

2.6.2 Promoting a Subordinate after Deletion

2.6.3 Promoting an Entire Subtree after Deletion

2.7 Levels in an Adjacency List Model

2.7.1 Numbering the Levels

2.7.2 Aggregation in the Adjacency List Model

Chapter 3 Path Enumeration Models

3.1 Finding the Depth of the Tree

3.2 Searching for Subordinates

3.3 Searching for Superiors

3.4 Deleting a Subtree

3.5 Deleting a Single Node

3.6 Inserting a New Node

3.7 Splitting up a Path String

3.8 The Edge Enumeration Model

3.9 Transitive Closure Model

3.10 Converting Path Enumeration Model to Adjacency List

3.11 Converting Path Enumeration Model to Nested Sets Model

Chapter 4 Nested Set Model of Hierarchies

4.1 Finding Root and Leaf Nodes

4.2 Finding Subtrees

4.3 Finding Levels and Paths in a Tree

4.3.1 Finding the Height of a Tree

4.3.2 Finding Levels of Subordinates



The demand for SQL information and training continues to grow with the need for a database behind every website capable of offering web-based information queries. SQL is the de facto standard for database retrieval, and if you need to access, update, or utilize data in a modern database management system, you will need SQL to do it. The Second Edition of Joe Celko's Trees and Hierarchies in SQL for Smarties covers two new sets of extensions over three entirely new chapters and expounds upon the changes that have occurred in SQL standards since the previous edition's publication. Benefit from mastering the challenging aspects of these database applications in SQL as taught by Joe Celko, one of the most-read SQL authors in the world.

Key Features

  • Expert advice from a noted SQL authority and award-winning columnist who has given 10 years of service to the ANSI SQL standards committee
  • Teaches scores of advanced techniques that can be used with any product, in any SQL environment
  • Offers graph theory and programming techniques for working around deficiencies and gives insight into real-world challenges


Database application developers (from enterprise-level application builders to small business developers)


No. of pages:
© Morgan Kaufmann 2012
Morgan Kaufmann
eBook ISBN:
Paperback ISBN:

About the Authors

Joe Celko Author

Joe Celko served 10 years on ANSI/ISO SQL Standards Committee and contributed to the SQL-89 and SQL-92 Standards. Mr. Celko is author a series of books on SQL and RDBMS for Elsevier/MKP. He is an independent consultant based in Austin, Texas. He has written over 1200 columns in the computer trade and academic press, mostly dealing with data and databases.

Affiliations and Expertise

Independent Consultant, Austin, Texas