I want to write an online database that displays 4-generation pedigrees. Can anyone point me to a tutorial/web site on how to do this? I've written several online databases in asp, but can't figure out how to do this particular algorithm. Any help appreciated.
Basically I have a list of about 400,000 horses each with a unique ID code. In each individual horses record there is its mother and father identified by their ID codes. ie; three columns, the horse's ID, and it's mother and father's ID. So, when you display a horses four generation chart, it should all link uphorse, mother father, grandparents, great-grandparents etc.. It should be a common database task, but Ive searched everywhere on the web and in various books and cant find how to write and link up the SQL statements. Any help/pointers would be appreciated. cheersYour table design should be similar to the following:
Horse Id,Horse Detail,Fathers Id, Mothers Id
Using SELF JOIN (Relating the table to itself by aliasing) you can derive any number of elements in a hierarchy.
e.g. Data
Horse Id | Horse Detail | Father Id | Mother Id
1 | ABC | |
2 | DEF | |
3 | GHI |1 |2
4 | JKL |1 |2
5 | MNO | |
6 | PQR |1 |5
An addtional field Sex (F/M) may be useful for your application
Hope this helps.
No comments:
Post a Comment