Solved

Family tree - Oracle 10 Sql syntax

Posted on 2011-02-16
2
655 Views
Last Modified: 2012-05-11
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
Comment
Question by:tonMachine100
2 Comments
 
LVL 76

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 100 total points
Comment Utility
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
 
LVL 34

Accepted Solution

by:
Mark Geerlings earned 400 total points
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now