1 | WITH RECURSIVE |
2 | with_decendants(id, parent, name, content, level) AS ( |
3 | VALUES(2, 1, '', '', 0) |
4 | UNION ALL |
5 | SELECT |
6 | notes.id, |
7 | notes.parent, |
8 | notes.name, |
9 | notes.content, |
10 | with_decendants.level+1 |
11 | FROM notes, with_decendants |
12 | WHERE notes.parent=with_decendants.id |
13 | ) |
14 | SELECT * FROM with_decendants; |