Dear Cmaz:
The concept can be illusive. You have to be able to THINK the way the
software does.
Basically, any time you need access to two different rows in your table,
simultaneously, then you have a self-join. Or, in a hierarchy, you may need
access to 3, 4, or more different rows simultaneously. When this happens,
and you've realized the fact, you need to know which row is the one you know
about first, and make the others successively dependent. Then just build
the JOINs accordingly.
Sounds simple, but if you stumble trying to grasp it, it can be confounding.
I recommend you not struggle, but try to visualize it, even sketching what
is going on. Or write the relevant column values of a row across a piece of
paper, and cut it out to represent a row of data. Do this for the related
rows as well. Now arrange these scraps on the table the way the function
together. Sometimes, I think of the data in this way, being flexibly
arranged. The query code tells how we are to arrange them.
If it helps, think of an outline form, with each subsidiary row in the
hierarchy being indented from its "parent" row. Indeed, I have often
arranged a report where the first column IS indented like this. It's really
a way humans are accustomed to seeing this. Your data would look like:
MMMMMMM
KKKKK
HHHHHHH
WWWWWW
AAAAA
GGGGGG
NNNN
PPPPP
QQQQQQQ
OOOOOO
I have found the above appearance to be the best way to display the data to
humans. You have a maximum of 6 levels of hierarchy built in. A 6 way
UNION query will build a key value on which you can sort, and can assign the
indentation level for you, and you can get this on paper as shown above,
with other columns (not indented) showing any details stored with the data.
There are a couple of tricks to being able to do this well. PLEASE DO NOT
TRY THIS AT HOME! Well, you could, of course. Heck, I had to figure it out
for myself at one time. Well, somebody had to do the dirty work!
Tom Ellison