eu tenho uma tabela mysql como
MENU_ID MENU_NAME PARENT_ONE PARENT_TWO
1 home 0 0
2 home_sub 1 0
3 third_home 1 2
Eu quero o nome contra ID de pai um e pai dois com cada linha se tiver. eu tentei algo, mas está dando apenas um que tem pai um e dois valores como
MENU_ID MENU_NAME PARENT_ONE PARENT_TWO MENU_NAME MENU_NAME
3 third_home 1 2 home home_sub
mas eu quero
MENU_ID MENU_NAME PARENT_ONE PARENT_TWO MENU_NAME MENU_NAME
1 home 0 0
2 home_sub 1 0 home
3 third_home 1 2 home home_sub
this the query that i tried
SELECT a.*, b.MENU_NAME, c.MENU_NAME
FROM menu_table a JOIN menu_table b ON a.PARENT_ONE = b.MENU_ID
JOIN menu_table c ON a.PARENT_TWO = c.MENU_ID ORDER BY a.MENU_ID;
avançado agradeço se alguém puder me ajudar nisso!
Você deve usar a junção à esquerda (junção é um apelido para junção interna)
SELECT a.*, b.MENU_NAME, c.MENU_NAME
FROM menu_table a
LEFT JOIN menu_table b ON a.PARENT_ONE = b.MENU_ID
LEFT JOIN menu_table c ON a.PARENT_TWO = c.MENU_ID
ORDER BY a.MENU_ID;
Este artigo é coletado da Internet.
Se houver alguma infração, entre em [email protected] Delete.
deixe-me dizer algumas palavras