6
Good morning. How can I make a two column JOIN in the same table?
On the table quotation, has the column with cpf_cnpj from warhead and fate.
SELECT
cotacao.*,
clienteOrigem.ID_Cliente as origemIdcliente,
clienteOrigem.cpf_cnpj as origemCpfcnpj,
clienteOrigem.isento as origemIsento,
clienteOrigem.suframa as origemSuframa,
clienteOrigem.rsocial as origemRsocial,
clienteOrigem.nfantasia as origemNfantasia,
clienteOrigem.ie as origemIe,
clienteOrigem.im as origemIm,
clienteOrigem.cep as origemCep,
clienteOrigem.rua as origemRua,
clienteOrigem.num as origemNum,
clienteOrigem.comple as origemComple,
clienteOrigem.bairro as origemBairro,
clienteOrigem.cidade as origemCidade,
clienteOrigem.codMunicipio as origemCodMunicipio,
clienteOrigem.estado as origemEstado,
clienteOrigem.pais as origemPais,
clienteOrigem.email as origemEmail,
clienteDestino.ID_Cliente as destinoIdcliente,
clienteDestino.cpf_cnpj as destinoCpfcnpj,
clienteDestino.isento as destinoIsento,
clienteDestino.suframa as destinoSuframa,
clienteDestino.rsocial as destinoRsocial,
clienteDestino.nfantasia as destinoNfantasia,
clienteDestino.ie as destinoIe,
clienteDestino.im as destinoIm,
clienteDestino.cep as destinoCep,
clienteDestino.rua as destinoRua,
clienteDestino.num as destinoNum,
clienteDestino.comple as destinoComple,
clienteDestino.bairro as destinoBairro,
clienteDestino.cidade as destinoCidade,
clienteDestino.codMunicipio as destinoCodMunicipio,
clienteDestino.estado as destinoEstado,
clienteDestino.pais as destinoPais,
clienteDestino.email as destinoEmail
FROM cotacao
LEFT JOIN clientes clienteOrigem on clienteOrigem.cpf_cnpj = cotacao.origem
LEFT JOIN clientes clienteDdestino on clienteDdestino.cpf_cnpj = cotacao.destinatario
WHERE
ID_Cotacao = '3'
Besides the data of the quotation table, I need to get the data of the origin and the destination.
That’s possible?
You can put a sample of the table contents?
– bruno