This is sort of what I want to do, but MySQL doesn't seem to accept it.
SELECT Name, Content, Lft, Rht FROM Articles WHERE
(Lft > (SELECT Lft FROM Articles WHERE idArticle = 1))
AND WHERE
(Rht < (SELECT Rht FROM Articles WHERE idArticle = 1));
I'm implementing the modified preorder tree transversal algorithm, and I want to get all the children of an Article
using a single database query.
The Articles table looks like this:
Articles +=============+===========+ | Type | Name | +=============+===========+ | VARCHAR(45) | Name | +-------------+-----------+ | LONGTEXT | Content | +-------------+-----------+ | INT | Lft | +-------------+-----------+ | INT | Rht | +-------------+-----------+ | INT | idArticle | +-------------+-----------+
idArticle
is a primary key, and there are UNIQUE indexes on the Lft
and Rht
columns.
How might something like this be accomplished?
*Note: I'm currently using MySQL but I'd like to avoid any MySQL extensions where possible, because there are possible plans to move to another DB like Postgres or Oracle sometime in the future...