I need help with SQL code. I have two tables, the first is the table name
NameID Name 1 John 2 Paul 3 Jessica 4 Nancy 5 Sam 6 Jane 7 Jimmy
The second is the Family table
FamilyID NameID ChildID 1 1 2 2 1 3 3 2 4 4 3 5 5 3 6 6 5 7
The "NameID" and "ChildID" fields in the Family table are connected to the "NameID" field in the Name table. Therefore, if I put it in a tree, it will be like
John / \ Paul Jessica / / \ Nancy Sam Jane / Jimmy
I need SQL code that can find "all" parents for a specific record. For instance:
- I want to know all the parents from Jane, the results will be: Jessica, John
I want to know all the parents from Jimmy, the results will be: Sam, Jessica, John
I want to know all the parents from Nancy, the results will be: Paul, John
source share