Hello greater minds and I appreciate any help you can offer me.. .I'm desperate to resolve this after many diverse attempts.
I have a population of animals in a single table each with a PK, a code for the individual family member (text) and a code for the mother (text). The mother code only is known, fathers do not remain with the population and can't be identified. Each individual has a mother, and the family is made up of sisters, brothers (young males who have not yet left the family), cousins and their offspring in turn.
I have got a certain way with a variety of approaches:
I need to:
1. to find the oldest female in the family, her daughters and their offspring in descending date order.
2. to find the next oldest sister to that female, her daughters/sons, and their offspring etc for all sisters
3. to find oldest cousin to female x, her daughters, and their offspring etc.
For example, Lobelia is the oldest family member in the example below; she was born in 1980, her mother is Lucia. Her two youngest are sons born this year and in 2018. Four daughters are alive and listed in descending date order, with Latha (her daughter born in 2000) with two of her own offspring, 'LTH20' and 'Lox', again listed in descending date order. Lily is Lobelia's oldest sister (same mother Lucia) with her kids listed and so on.
Should I be using a nested subquery approach for this or a union query with subquery (which I've also tried, but failed to land the correct sort at the very end whereby sisters are together before cousins)?
I feel that perhaps I should be constructing a vba sql nested subquery statement, but I can't see how to construct the correct sql to find the next oldest, having dealt with the oldest etc.
I can send many constructs for my different attempts as attachments.
Thx a million for your time!
I have a population of animals in a single table each with a PK, a code for the individual family member (text) and a code for the mother (text). The mother code only is known, fathers do not remain with the population and can't be identified. Each individual has a mother, and the family is made up of sisters, brothers (young males who have not yet left the family), cousins and their offspring in turn.
I have got a certain way with a variety of approaches:
self-joins, linking individual code with mother in each case. This produces the correct order for each 'mother' with her offspring, but I can't arrive at the desired order
creating a hierarchy through a self join then a UNION query with subqueries at each level, producing depth, root and path for each individual in the population
vba sql loop - I feel that this may be the answer, but I need help with this
I need to:
1. to find the oldest female in the family, her daughters and their offspring in descending date order.
2. to find the next oldest sister to that female, her daughters/sons, and their offspring etc for all sisters
3. to find oldest cousin to female x, her daughters, and their offspring etc.
For example, Lobelia is the oldest family member in the example below; she was born in 1980, her mother is Lucia. Her two youngest are sons born this year and in 2018. Four daughters are alive and listed in descending date order, with Latha (her daughter born in 2000) with two of her own offspring, 'LTH20' and 'Lox', again listed in descending date order. Lily is Lobelia's oldest sister (same mother Lucia) with her kids listed and so on.
Should I be using a nested subquery approach for this or a union query with subquery (which I've also tried, but failed to land the correct sort at the very end whereby sisters are together before cousins)?
I feel that perhaps I should be constructing a vba sql nested subquery statement, but I can't see how to construct the correct sql to find the next oldest, having dealt with the oldest etc.
I can send many constructs for my different attempts as attachments.
Thx a million for your time!