Robert Zajda uttered:
Hello
I have a table
CREATE TABLE acategories {
id integer not null primary key
category string
parent_category integer references acategories.id
)
query:
SELECT
a.id AS 'id',
a.category AS 'Category',
b.category AS 'Parent category'
FROM acategories AS a
LEFT JOIN acategories AS b ON a.parent_category=b.id
everything works ok, but i need to add new field with deepness level
of each row.
Is it possible ?
Yes, just add the field and maintain it yourself, but you've now created
redundent data that must be maintained, going against the point of
normalisation.
If you need the depth of a node, then simply do an iterative count using
SELECT to walk from the node to the root category.
You can represent tree data using a method such as Modified Preorder Tree
Traversal:
http://www.sitepoint.com/article/hierarchical-data-database/2
Insert and deleting nodes is more involved, but retrieving sub-trees is
faster and doable with a single query.
Thanks
Robert
Christian
--
/"\
\ / ASCII RIBBON CAMPAIGN - AGAINST HTML MAIL
X - AGAINST MS ATTACHMENTS
/ \
-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------