This may be slightly confusing for a beginner, but the best solution I have seen (and I have looked for many years...) is the one I found at:
'Genealogical Representation of Trees in Databases', by Miguel Sofer http://www.utdt.edu/~mig/sql-trees
This method involves having the 'application' (maybe vbscript in access, or php for a mysql backend) create an 'id' structure that represents the tree hierarchy. From a previous document I wrote:
An example of the categoryId structure might be:
00a
00a001
00a001001
The 'id' of a category is made up from a multiple of set-width of characters, depending on the application using the database – a 3-character width is a good start.
This id represents the 'number' of the category, but, to save resources, encoded to higher than base 10, e.g. base 32 (the highest available through a particular PHP function). So, each 'node' of category has 3 characters, which represents a number encoded in base32: i.e. three characters can represent numbers up to:
32*32*32 = 32,768
This infers that each 'node' can have over 32,000 categories. These three characters (the 'id') are then appended onto the 'id' of the parent category. Thus, the maximum 'depth' of the tree will be the maximum size of the database id field divided by the number of characters:
For a MySQL VARCHAR field: 255/3 = 85
This means that the tree can have 85 levels (a 'depth' of 85), each containing 32,000 nodes.
The childCount field is used to store the actual 'number' of a nodes highest child id, so that if a new child is added to a node, simply increment this field, encode as base 32, and append to the parent id to get the new child id.
This method of storing hierarchical structures allows us to perform usually complex queries with little processing power:
The depth of any node can be calculated simply by dividing the number of characters in the id (e.g. 3, 6, 9, etc.) by the number of characters used to represent each node (e.g. 3).
A sub-node tree can be found by selecting categories with 'id like '00100a%', where 00100a is an example of the current category.
The descendants of the node (i.e. those from the node up to root) can be found easily be simply recursively removing the last three characters from the id.
Sorry, that's all a bit in-depth - read the paper at the above link for a good analysis.