Select data even if it does not appear on all tables

1

I have the following Query :

SELECT 
    public.suprimento.suprimento, 
    public.estoque.numeroserie, 
    public.fornecedor.nome as fornecedor, 
    public.estoque.data as dataentrada, 
    public.estoque.numeronotafiscal,
    public.empresa.nome as empresa,
    public.entrega.data as datasaida,
    public.entrega.notafiscalhss,
    public.entrega.usuario,
    public.entrega.usuariohss,
    public.lotesretornosuprimento.dataretorno,
    public.lotesretornosuprimento.laudo,
    public.lotesgarantiastatus.numeroserieretornado
FROM
    public.estoque, 
    public.suprimento,
    public.fornecedor,
    public.entregaitem,
    public.entrega,
    public.empresa,
    public.lotesretornosuprimento,
    public.lotesgarantiastatus
where 
    public.suprimento.codigo = public.estoque.codigosuprimento and
    public.estoque.codigofornecedor = public.fornecedor.codigo and
    public.entregaitem.codigoestoque = public.estoque.codigo and 
    public.entregaitem.codigoentrega = public.entrega.codigo and
    public.empresa.codigo = public.entrega.codigoempresa and
    public.lotesretornosuprimento.numeroserie = public.estoque.numeroserie and
    public.lotesgarantiastatus.numeroserieenviado = public.estoque.numeroserie

That returns me the whole course of the supply from the moment it is bought until the return to our supplier for correct disposal or for guarantee, my need however is to also display the supplies that way bought but still were not sent to any client or returned to the vendor, in the way I mounted the Query I only select the supplies that had the complete track:

Purchase - > Sale - > Return Supplier

It is possible to adapt this Query so that it also returns the following situations:

Purchase - > Sale

And also when the supply is only purchased:

Buy

    
asked by anonymous 26.02.2018 / 17:51

1 answer

0

What you should do is to put LEFT JOIN on tables that do not exist data, eg:

SELECT 
    CAMPO1, CAMPO2, CAMPO3, CAMPO4, CAMPO5, CAMPO6
FROM
    TABELA T1
INNER JOIN 
    TABELA T2 ON T2.CAMPO = T1.CAMPO
LEFT JOIN 
    TABELA T3 ON T3.CAMPO = T2.CAMPO
    
26.02.2018 / 17:56