?
Solved

Family tree - Oracle 10 Sql syntax

Posted on 2011-02-16
2
Medium Priority
?
676 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 77

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 400 total points
ID: 34907206
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 35

Accepted Solution

by:
Mark Geerlings earned 1600 total points
ID: 34909765
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

Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.
Suggested Courses

765 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