Two tables returning a single result

1
select
        cliente.codcliente,
        cliente.dt_cadastro
from cliente
where cliente.codcliente in ('00000224', '00000170', '00061825', '01009838')
order by cliente.codcliente

selectnfsaidc.codcliente,nfsaidc.numnf,nfsaidc.dt_emissao,nfsaidc.totalnffromnfsaidcwhereNFSAIDC.CODCLIENTEin('00000224','00000170','00061825','01009838')orderbynfsaidc.numnf

Personally,IneedtoretuneonlyonerowofeachclientwiththecolumnsCODE,DT_CADASTRO,NUMNF,DT_EMISSAO,TOTALNF.Theresultwouldbethedatethatthecustomerwasregisteredwiththefirstpurchasemade.TheresultIneedwouldbetheimagebelow:

I am using IBEXPERT with Firebird 2.1 but I accept suggestions from other platforms.

    
asked by anonymous 20.10.2017 / 18:39

1 answer

1

Charles, I can not simulate here, but the concept (SQL) is this:

SELECT CL.codcliente, CL.dt_cadastro, NF.numnf, MIN(NF.dt_emissao), NF.totalnf
FROM nfsaidc NF
LEFT OUTER JOIN cliente CL ON CL.codcliente = NF.codcliente
GROUP BY CL.codcliente
ORDER BY CL.codcliente
    
20.10.2017 / 19:04