3
I took an example of people registering with the following structure:
I’m trying to make a SELECT
in tblPessoa
with JOIN
with the intention that select returns data from the table in which Id exists, select:
select tblPessoaJuridica.Nome as [NomePJ], tblPessoaFisica.Nome as [NomePF], tblPessoaProdutor.Nome as [NomeProdutor]
from tblPessoa
left join tblPessoaFisica on tblPessoaFisica.IdPessoaFisica = tblPessoa.idPessoa
left join tblPessoaJuridica on tblPessoaJuridica.IdPessoaJuridica = tblPessoa.idPessoa
left join tblPessoaProdutor on tblPessoaProdutor.IdPessoaProdutor = tblPessoa.idPessoa
where idPessoa = 2547
However I have read that the left Join is slow, example:
Slow query in SQL Server with left Join
Left Joins are what I want but they are very slow?
among others.
What would be the most efficient way to replace this left Join ?
EDIT
I put 'NAME' just for example, the PJ has Social Reason, the PF has the Name and the Producer has the name of the Farm/Farm/Etc. This diagram is an example I took.
As far as I know has not the such efficient way to replace the left Join and return the same records.
– Marco Souza