Solved

Family tree - Oracle 10 Sql syntax

Posted on 2011-02-16
2
673 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 100 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 400 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even withinā€¦
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

707 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