Good morning. How do I make a JOIN, two column in the same table?
In the quote table, you have the column with the ogirem and destination cpf_cnpj.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'
In addition to the quote table data, I need to get the source and target data.
Is this possible?