"one way to get tree-structured data from a relational database with a SQL query is to write a recursive CTE (Common Table Expressions), which are just as fun as they sound."
I promise you that CTEs, even recursive ones, are not scary and that once you get the hang of them are actually fun.