Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Family tree - Oracle 10 Sql syntax

Posted on 2011-02-16
2
Medium Priority
?
679 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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

636 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