I have this a tree structured table with a materialized path column (matpath). The data looks like this:
ID MATPATH PARENT
---------------------
1 NULL NULL
2 1. 1
3 1.2. 2
4 1.2.3. 3
5 1.2. 2
6 1.2.3.4. 4
7 1.2.5. 5
etc
Given the ID, how can I get all elements that are above (one query) or below (anther query)? For example, if the ID is 7, I want to select rows with IDs 1, 2 and 5 in addition to 7. If the given ID is 3, select 1, 2 and 3. And so on.
Thank you.