Nested Set is a model or standard for storing multi-level hierarchies in a database. In this article we’ll be using it to store categories for a shop, but the logic is the same for any type of multi-level resource.

Storing categories in a database can sometimes be pretty complicated to query if you have a hierarchy larger than 2 levels. Let’s consider the following example that I’ve borrowed from Nested Set’s Wikipedia page:

Continue reading…