0
I have a SELECT with several LEFT JOIN, but I need to consider all of these LEFT JOIN in some conditions, already in another condition I need to disregard a JOIN done.
As an example below:
SELECT *
FROM
TabelaTotal TT
LEFT JOIN Client Cli ON Cli.FKTT = TT.Id
LEFT JOIN Tabela1 CN ON CN.FK_Cli = Cli.ID
LEFT JOIN Produto Pr ON Tabela1.ID = Pr.FK_Tabela1
WHERE
--Condição considera todos os JOINS
and
(
( CT.Name <> 'A' and
Pr.QTD > 0 and
)
--Condição que eu preciso desconsiderar o Relacionamento com a Tabela Produto
OR
( CT.Name = 'A'
)
)
--Como fazer a condição CT.Name = 'A' desconsiderar o LEFT JOIN da tabela Produto
--LEFT JOIN Produto Pr ON Tabela1.ID = Pr.FK_Tabela1
LEFT JOIN already allows you to disregard the relationship! Do you want to pick only where the relationship is not valid? That’s it?
– Danilo Gomes
I want to make the relationship with the Product table only as CT.Name <> 'A' Case CT.Name = 'A' I want to make the same select but I want to disregard the relationship with the Product table, using the LEFT it returns values, I want not even make the relationship with Product
– twister8
First of all, I don’t see any tables renamed as
CT
, is not clear the question, itsLEFT JOIN
return all data from these tables and yourWHERE
filter where(CT.Name <> 'A' and Pr.QTD > 0 and )
or(CT.Name = 'A')
, what problem here?– Marco Souza