[eluser]MEM[/eluser]
Despite the fact that I'm using the same table, I'm having a method on my model for retrieving the categories, and another method on my model for retrieving the subcategories and sub-subcategories.
How would a query like this, help me to return an array where my firstlevel elements should be my subcategories, and my secondlevel elements my sub-subcategories?
Code:
SELECT FistLevel,SecondLevel FROM (
(SELECT ID as 'FirstLevel' from myTable) 'L1'
Left Join (SELECT ID as 'SecondLevel' from myTable L2) on L2.ParentID = L1.'FirstLevel'
)
Anyway, I'm having a hard time trying to understand this query.
The FirstLevel and SecondLevel are aliases? What are L1 and L2 ?
Can you or anyone else, properly describe in text what's going on on this query so that I can understand it?
I will then have something like this:
1,2
1,6
2,9
10,NULL
On the first row I will get an id of 2 and a parent_id of 1. So 1 should be my subcategory, and 2 my sub-subcategory... ?
On the second row I will get an id of 6, with a parent_id of 1, so 1 should be my subcategory, and 6 my sub-subcategory...
Later, on number 10
So 10 should be my subcategory and I will have no sub-subcategory here...
Am I near? Or Am I lost?
Regards,
Márcio