Recursive Queries
Modern relational database systems - like PostgreSQL - give You the possibility to query data directly in recursive manner..
So if You have data that is linked in any way, maybe some kind of parent and child records, You'll be able to list the whole relationship in one query. Important with recursion will be an exit strategy, in case Your data is deeply related. Queries could, under certain conditions, never return
You benefit from high performance - the query will execute as fast as possible.
Writing recursive queries is a challenging task, but the result is always worth doing it.