Recursive CTEs: Trees and Graphs in SQL
One recursive SQL query finds that Asha has 9 people under her; another goes round a loop until a LIMIT stops it.
Video #126 ยท SQL and analytics
Steps in the video
Files
- org.py (23 lines)
- queries.py (49 lines)
- run.py (11 lines)
Tested with
Python 3.12.15
What this does not show
Ten made-up people and five made-up towns, run only in SQLite; text paths with instr will not scale to big graphs.
Sources
Learning IT by Example.