Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 HELP PLEASE!!!

Author  Topic 

stalian4002
Starting Member

3 Posts

Posted - 2009-01-06 : 12:09:24
I am writing a program to store family tree data, some what similar to the
GEDCOM format. I need help writing a sql query to get all the relatives and
determine the relation (father's mother, brother's wife, etc) for a
particular user. Here is my basic table structure:

Table Users
-UserName (PK)
-FirstName
-AsChildInFamilyID
-AsSpouseInFamilyID
-AsParentInFamilyID

Table Families
- FamilyID (PK)
- MarriageDate

Table FamilyMembers
- FamilyMemberID (PK)
- FamilyID (FK)
- UserName
- Relation (0 - Husband, 1 - Wife, 3-Child)

---> So, given any user, I need to find all the relatives (traverse up as
well as down the tree) and also calculate the relationships as I go along.
The relation column stores the relation specific only to the family (that too
not very accurate, because for instance the husband is actually the father to
the child, not the husband), but I need to "update" the Relation field to
include the depth of the traversal.

Based on my table structure, a family unit is husband, wife and
children....I somehow have to recursively find all the ascendants,
descendants, etc...

Any help on how I can do this would be great

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-06 : 12:12:23
are you using sql 2005?
Go to Top of Page

stalian4002
Starting Member

3 Posts

Posted - 2009-01-06 : 17:23:50
im using mysql
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-01-06 : 17:26:19
You should post your question on a MySql site then. This site is for Microsoft SQL Server. There is a MySql forum over at dbforums.com and even mysql.com has one.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -