0
I have 3 tables which I want to bring only data from table 1, if you do not have in table 1 to bring data from table 3 , if you have data in the 3 tables bring only from table 3. My problem is that when I have the data in the 2 tables this bringing duplicate, as it brings the data from table 1 and table 3.
Example:
SELECT B.CodigoPasta AS Pasta, B.Tipo_Acao as TipoAcao, SUM(B.ValorNB) AS Valor, G.Usuario, G.DataCriacao FROM TB_Contrato AS B
INNER JOIN TB_Processamento AS A
ON B.Id = A.IdContrato
LEFT JOIN TB_StatusNegociacao AS G
ON G.IdProcessamento = A.Id
GROUP BY B.CodigoPasta,B.Tipo_Acao,G.Usuario,G.DataCriacao
ORDER BY g.DataCriacao desc
Tried using only Left Join to see if it requires at least one result?
– DbaAlone
Coloquei da forma abaixo porém ainda continua repetindo o B.codigoPasta SELECT DISTINCT B.CodigoPasta AS Pasta, B.Tipo_Acao as TipoAcao, SUM(B.ValorNB) AS Valor, G.Usuario, G.DataCriacao FROM TB_Contrato AS B
LEFT JOIN TB_Processamento AS A
ON B.Id = A.Idcontract LEFT JOIN Tb_status ON G.Idprocessing = A.Id GROUP BY B.Codefolder,B.Type_action,G.User,G.Datacreation ORDER BY g.Datacreation desc
– Ricardo