The tree from the videos:
stateDiagram-v2
Fruits --> Apple
Fruits --> Mango
Apple --> Green Apple
Apple --> Yellow Apple
Apple --> Red Apple
Here you can find the SQL code for the nested sets model written in PostgreSQL 13.3-1.pgdg100+1
- Create catogires table
- Create nodes
- Find the root node
- Finding the immediate children of a node
- Find how many immediate children a node has
- Finding the leaf nodes with a sub query
- Finding the leaf nodes with a left join
- Find the full path
- Find the full path as a list with depth or level
- Find the full path from a node down
- Find the full path from a node up