I need your help with this request, I can’t decide. Here's what, say, I have a table like this:
Father | Son 1 | 2 1 | 3 1 | 4 3 | 5 3 | 6 2 | 7 4 | 8 5 | 9 6 | 10
So, as you see, the table represents the relationship of father and son, I need to find all the sons (and sons of the sons) of one father, for example, if Im looking for sons of the number 1, we get a table like this
Father | son 1 | 2 1 | 3 1 | 4 1 | 5 1 | 6 1 | 7 1 | 8 1 | 9 1 | 10
If I look at sons from number 3, we get:
Father | son 3 | 5 3 | 6 3 | 9 3 | 10
Well, I think you understand my point. The next problem is that I have to do this for every father in the table. Therefore, at the end, the table will look like this:
Father | son 1 | 2 1 | 3 1 | 4 1 | 5 1 | 6 1 | 7 1 | 8 1 | 9 1 | 10 3 | 5 3 | 6 3 | 9 3 | 10 2 | 7 4 | 8 5 | 9 6 | 10
pretty similar to a tree. I tried to find out this query for a while without having time. I made code like this
WITH son AS (
But this does not work for each father at the same time, and the final table is slightly different, she only has the identifier of the son. Example
son 3 4 5 6 7
I hope you help me.
source share