Source: /cirosantilli/sql-tree-traversal

= SQL tree traversal
{c}
{tag=Tree traversal}

Example: \a[nodejs/sequelize/raw/tree.js]

* Implementation agnostic
  * https://stackoverflow.com/questions/192220/what-is-the-most-efficient-elegant-way-to-parse-a-flat-table-into-a-tree
  * https://stackoverflow.com/questions/5508985/recursive-query-for-adjacency-list-to-preorder-tree-traversal-in-sql DBMS agnostic specifically asking not to modify adjacenty list data structure
* <Postgres>
  * https://stackoverflow.com/questions/67848017/simple-recursive-sql-query
  * https://stackoverflow.com/questions/28688264/how-to-traverse-a-hierarchical-tree-structure-structure-backwards-using-recursiv
  * https://stackoverflow.com/questions/51822070/how-can-postgres-represent-a-tree-of-row-ids
  * depth first
    * uspecified depth first variant
      * https://stackoverflow.com/questions/50098759/postgres-nested-records-in-a-recursive-query-in-depth-first-manner
      * https://stackoverflow.com/questions/59463176/how-to-perform-depth-first-search-in-postgresql
      * https://stackoverflow.com/questions/30336265/postgresql-recursive-cte-results-ordering
    * <preorder DFS>
      * https://dba.stackexchange.com/questions/63153/how-do-i-sort-the-results-of-a-recursive-query-in-an-expanded-tree-like-fashion
      * https://stackoverflow.com/questions/65247873/preorder-tree-traversal-using-recursive-ctes-in-sql/77276675\#77276675
  * <breadth-first> https://stackoverflow.com/questions/3709292/select-rows-from-table-using-tree-order
* <MySQL>
  * https://stackoverflow.com/questions/8252323/mysql-closure-table-hierarchical-database-how-to-pull-information-out-in-the-c asks how to use a specific order (<preorder DFS>) with <closure table>
* <Microsoft SQL Server>
  * https://stackoverflow.com/questions/14274942/sql-server-cte-and-recursion-example