[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 684
  • Last Modified:

Family tree - Oracle 10 Sql syntax

I'm thinking about producing a 'family tree' style report.

The table im working with (t_relationships) contains the subject and personal relationships to the subject. I've attached three family groups as sample data.

At this stage im just thinking about whether its possible in sql and if so the logic behind it.

I'm also working with a reporting tool called actuate which would allow me to dynamically position the data items on a page (based on the family composition) but i'm reluctant to take this option due to the heavy programming that this would involve. I'm therefore wondering if I can do anything in sql to get this result or at least make the task easier for when the sql is dropped into actuate.

Any ideas are apprecated.
family-eg.xls
0
tonMachine100
Asked:
tonMachine100
2 Solutions
 
slightwv (䄆 Netminder) Commented:
I don't see the hierarchical relationships.  From a data standpoint, how do you know the relationships?

Once you have that relationship in the data, it's straight forward with Oracle:

Hierarchical Queries

http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries003.htm
0
 
Mark GeerlingsDatabase AdministratorCommented:
Oracle can do hierarchical queries (like: for family trees, bills-of-material, organizational charts, etc.) from data in a single table if the data is structured to support that.  For hierarchical queries in Oracle two special clauses are required: "start with" and "connect by prior".

For example if you have a "familes" table defined like this:
parent_id  number,
child_id     number

and you have data like this:
1,2
1,3
2,4
2,5
3,6
3,7
3,8

your query would be:
select parent_id, child_id
from families
start with 1
connect by prior child_id = parent_id

(I think I have the order of that "connect by prior" clause speciifed correctly, but I didn't test it.  If that doesn't work, then it should be like this:
connect by prior parent_id = child_id)

One way will allow you to start with the parent and find all decendents.  The other way would allow you to display the tree in reverse, by starting with a child to find all of his/her ancestors.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now