In my MySQL-Database i have one table called units with the structure like this:
ID, Name, parentUnitID, UnitTypeID, ...
Is it possible to generate a complete Unit-Chain with one query and one ID as the starting point? Cascading the query as long as there are more parents for the given ID? I can't find a way generating this without the depth limitation.
It is possible that the given ID has a parent which also itself has a parent, which also might have one, ...etc.
Edit:
The Result I am expecting is something like this:
IDDepth1, IDDepth2, IDDepth3, ..., NameDepth1, NameDepth2, NameDepth3, ...
Or
UnitTypeID1, Name1,
UnitTypeID2, Name2,
UnitTypeID3, Name3,
...
To get the complete Unit-Chain for the given ID and parse it in PHP to build a cascading array.
Edit2:
I tried something like this
SELECT ID, Name
FROM Units as u1
WHERE UnitTypeID = "4"
AND EXISTS (
SELECT ID, Name
FROM Units as u2
WHERE UnitTypeID = "5"
AND u2.ParentUnitID = u1.ID
AND EXISTS (
SELECT ID
FROM Units as u3
WHERE ID = "1692820"
AND u3.UnitTypeID = "6"
AND u3.ParentUnitID = u2.ID
)
);
But first it is static and second the result from EXISTS is not part of the SELECT itself.