Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

LHR

[Resolvido] JOIN com mesmo nome

Recommended Posts

Olá pessoal,

 

Estou tendo dificuldades pra fazer a seguinte query:

 

Select ITEM.CAPCODEITEM, MODELO.NOMEMODELO, DEFEITO.NOMEDEFEITO, 
MANUTENCAO.DATAMANUT, MANUTENCAO.saidamanut FROM ITEM
join MANUTENCAO on (MANUTENCAO.CODITEMMANUT=ITEM.CODITEM)
join MODELO on (MANUTENCAO.MODELOMANUT=MODELO.CODMODELO)
join DEFEITO on (MANUTENCAO.DEFCONSTATADOMANUT=DEFEITO.CODDEFEITO)
join DEFEITO on (MANUTENCAO.DEFALEGADOMANUT=DEFEITO.CODDEFEITO)

O problema ae é nesse JOIN DEFEITO.

Eu possou 2 campos que têm chave estrangeira com o campo CODDEFEITO: Defalegadomanut e Defconstatadomanut.

Como faço pra fazer esse JOIN funcionar?

 

Obrigado.

 

Até mais!

Compartilhar este post


Link para o post
Compartilhar em outros sites

Tente renomear as tabelas, ficando:

 

 

Select ITEM.CAPCODEITEM, MODELO.NOMEMODELO, DEFEITO1.NOMEDEFEITO as NOMEDEFEITO1, DEFEITO2.NOMEDEFEITO as NOMEDEFEITO2,
MANUTENCAO.DATAMANUT, MANUTENCAO.saidamanut
FROM ITEM
join MANUTENCAO on (MANUTENCAO.CODITEMMANUT=ITEM.CODITEM)
join MODELO on (MANUTENCAO.MODELOMANUT=MODELO.CODMODELO)
join DEFEITO as DEFEITO1 on (MANUTENCAO.DEFCONSTATADOMANUT=DEFEITO1.CODDEFEITO)
join DEFEITO as DEFEITO2 on (MANUTENCAO.DEFALEGADOMANUT=DEFEITO2.CODDEFEITO)

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.