Domanda

I do not know how to select query recursive..

I have table like this:

idmenu   idparent     Title
  1         0         menu_parent1
  2         1         menu_child2
  3         1         menu_child3
  4         0         menu_parent4
  5         4         menu_child5
  6         4         menu_child6

how do the results like this

  idmenu    idparent          Title
  1       menu_parent1     menu_parent1
  2       menu_parent1     menu_child2
  3       menu_parent1     menu_child3
  4       menu_parent4     menu_parent4
  5       menu_parent4     menu_child5
  6       menu_parent4     menu_child6

anyone help me..thanks

È stato utile?

Soluzione

zero doesnt refer to something, can you fix it? the answer may be like this

SELECT aa.idmenu,
       bb.title AS idparent,
       aa.title 
FROM [yourtablename] aa
     LEFT OUTER JOIN [yourtablename] bb 
                  ON aa.idmenu=bb.idmenu
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top