Category Archives: SQL

Recursive common table expressions (CTE) for arbitrary depth hierarchies

The challenge of storing an arbitrary depth hierarchy isn’t so much with the storing of it as it is with the querying it and rendering it in a useful fashion. Given a simple hierarchy stored in a table that has a self-referential parent_id such as: With some sample data: We can extract the data: Which […]

Read More