Hi All,
Really hoping that someone here can help me with this. I designed a database table to hold a load of related records, so they could all be associated together. It is basically a parent child, grandchild relationship within this table.
Now what i need to be able to do, is to query this table, with either a parent, a child or a grandchild ID, and for it to then return the parents text field.
The data structure is:
So, with the above data, I want to be able to query the table with an OffenceID of say 8, and for it to return "ParentOffence2". I thought I'd be able to get around this by joining the table to itself three times, but that isn't working.
Anyone know of a clever way of doing this?
Thanks in advance
Tony
Really hoping that someone here can help me with this. I designed a database table to hold a load of related records, so they could all be associated together. It is basically a parent child, grandchild relationship within this table.
Now what i need to be able to do, is to query this table, with either a parent, a child or a grandchild ID, and for it to then return the parents text field.
The data structure is:
Code:
OffenceID ParentID OffenceName
1 0 ParentOffence1
2 1 ChildOffence1
3 2 GrandChild1
4 2 GrandChild2
5 2 GrandChild3
6 0 ParentOffence2
7 6 ChildOffence2
8 7 GrandChild4
So, with the above data, I want to be able to query the table with an OffenceID of say 8, and for it to return "ParentOffence2". I thought I'd be able to get around this by joining the table to itself three times, but that isn't working.
Anyone know of a clever way of doing this?
Thanks in advance
Tony