Dev Helpers
← Back

Traverse a small tree

Traverse a small tree using SQLite.

Open this example in the interactive library

Source code

WITH RECURSIVE edges(p,c) AS (VALUES('root','a'),('root','b'),('a','c')), walk(n) AS (VALUES('root') UNION ALL SELECT c FROM edges JOIN walk ON p=n) SELECT n FROM walk;

Sample output

[
  {
    "n": "root"
  },
  {
    "n": "a"
  },
  {
    "n": "b"
  },
  {
    "n": "c"
  }
]