0
I have the following table containing self-relationship between the idcategoria and parent columns:
idcategoria categoria pai
1 Camisetas 0
2 Regata 1
When an added category does not have a parent category the column value will be zero, and otherwise the parent column will have the idcategory value of its corresponding parent category. I tried it as follows, but it didn’t work because the parent column was sometimes zero, which would force the display of only values with parent categories. Follows:
SELECT c.*, p.categoria AS catpai FROM categoria AS c, categoria AS p WHERE p.pai = c.idcategoria;
The intention is to take as a result all the categories and the name of the PAI categories that have parent category. I will only work with two levels.
You want to catch only two levels?
– bfavaretto
It is true, corrected.
– touchmx
Exactly, I need all categories and in the output the name of the PAI categories. However I will only work with two levels.
– touchmx