da una query del genere come faccio ad ottenere un risultato???
mi spiego meglio:
ho una tabella categoria strutturata cosi
id | nome | Pid
1 | padre 1 | 0
2 | padre 2 | 0
3 | figlio di 1-1 | 1
4 | figlio di 2-1 | 2
5 | padre 3 | 0
6 | figlio di 2-2 | 2
7 | figlio di 3-1 | 5
8 | figlio di 1-2 | 1
9 | padre 4 | 0
La query è la seguente:
SELECT tab1.id as IDpadre, tab1.nome as padre, tab2.id as IDfiglio,tab2.nome as figlio from TABELLA as tab1 join TABELLA as tab2 on(tab1.id=tab2.pid or (tab1.pid=0 and tab1.id=tab2.id)) order by IDpadre,IDfiglio;
come faccio a gestire un output per questa interogazione in modo che mi visualizzai
categorie
padre 1
-figlio 1
-figlio 2
padre 2
-figlio 1
-figlio 2
spero qualcuno possa aiutarmi .....
grazie