Hi,
I have a quick question, I hope. The issue is quite simple. I'm trying to create a 5-level (purposely limited to 5) hierarchical query, that's returning odd results. For simplicity, I'll just include the relevant stuff.
I have a table, called, "CONTENT_Items". This table has an ItemID PK and a ParentItemID column, both of type int. This table currently has exactly one row in it:
---
ItemID, ParentItemID
1, 0
---
When I run the following query:
...I should get the following results:
c1ItemID, c2ItemID, c3ItemID, c4ItemID, c5ItemID
1, NULL, NULL, NULL, NULL
...but instead, I get:
c1ItemID, c2ItemID, c3ItemID, c4ItemID, c5ItemID
1, NULL, 1, NULL, 1
Why is this? And how do I get the desired (first) set of results instead?
Many thanks!
Katie
I have a quick question, I hope. The issue is quite simple. I'm trying to create a 5-level (purposely limited to 5) hierarchical query, that's returning odd results. For simplicity, I'll just include the relevant stuff.
I have a table, called, "CONTENT_Items". This table has an ItemID PK and a ParentItemID column, both of type int. This table currently has exactly one row in it:
---
ItemID, ParentItemID
1, 0
---
When I run the following query:
SQL:
SELECT c1.`ItemID` c1ItemID,
c2.`ItemID` c2ItemID,
c3.`ItemID` c3ItemID,
c4.`ItemID` c4ItemID,
c5.`ItemID` c5ItemID
FROM `CONTENT_Items` c1
LEFT JOIN `CONTENT_Items` c2 ON c2.ParentItemID = c1.ItemID
LEFT JOIN `CONTENT_Items` c3 ON c3.ParentItemID = c2.ItemID
LEFT JOIN `CONTENT_Items` c4 ON c4.ParentItemID = c3.ItemID
LEFT JOIN `CONTENT_Items` c5 ON c5.ParentItemID = c4.ItemID
WHERE c1.ParentItemID = 0
...I should get the following results:
c1ItemID, c2ItemID, c3ItemID, c4ItemID, c5ItemID
1, NULL, NULL, NULL, NULL
...but instead, I get:
c1ItemID, c2ItemID, c3ItemID, c4ItemID, c5ItemID
1, NULL, 1, NULL, 1
Why is this? And how do I get the desired (first) set of results instead?
Many thanks!
Katie