Quote:
I think part of the problem is I'm not sure of the correct language for what I want to achieve so my searching isn't returning anything very useful. |
What you described is a general undirected graph. A tree is special
case of a graph and it is usually directed. Dover Books has several
good cheap intro books on the topic, but the easiest reads are:
Introductory Graph Theory by Gary Chartrand (ISBN: 0486247759)
Introduction to Graph Theory by Richard J. Trudeau (ISBN: 0486678709)
The only way I have found to do this in SQL is with a table of Nodes
and a table of Edges. After that, you mimic procedural code from a
book on graph algorithms. I like the pseudo-code in
Algorithmic Graph Theory by James A. McHugh (ISBN 0-13-023615-2)
Quote:
My final aim is to display a diagram showing the relationships
between nodes, so, first, I need to store these nodes and their
|
relationships in a database, then to query them so I can create my
diagram. <<
We don't do diagrams in SQL; that is the job of the front end. The
Edges table has the relationships in it and you can probably pass them
to an drawing tool of some kind.
Quote:
My nodes have relationships with other nodes, the relationships are two way (so if A likes B, then B likes A, or if the road goes from A to B, then it also goes from B to A), I started with a tree, but some nodes have more than one parent [sic], and sometimes have a parent [sic] that is it's other parent's [sic] great uncle - I've not used a tree like this before. |
That is not a tree by definition. As quick check, the number edges in
a tree is (# of nodes)-1. Then you need to check for cycles; a tree
has no cycles.
Quote:
These are some of the relationships I have thus far: |
1-2
1-3
1-4
3-4 <-- CYCLE!!
4-5
3-5 <-- CYCLE!!
5-6
2-6 <-- CYCLE!!
<<