Two tables returning only one result

Asked

Viewed 55 times

1

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

Resultado 1

select  nfsaidc.codcliente,
        nfsaidc.numnf,
        nfsaidc.dt_emissao,
        nfsaidc.totalnf
from nfsaidc
where NFSAIDC.CODCLIENTE in ('00000224', '00000170', '00061825', '01009838') 
order by nfsaidc.numnf

Resultado 2

Guys, I need to retouch only one row of each client with CODCLIENTE, DT_CADASTRO, NUMNF, DT_EMISSAO, TOTALNF columns. The result would be the date the customer was registered with the first purchase made. The result I need would be the image below: Resultado esperado

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

  • You have to eliminate the zeroes on the left too ?

  • No need!! The formwork that was wrong

  • Charles, has your problem been solved? Is there anything else I can explain?

1 answer

1

Charles, I can’t simulate it 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
  • Depending on the sql engine, it will give code error, as you are grouping only by one column and returning several

  • Right, so you can try using the DISTINCT. I must not have used Firebird or 5x in life ! rs

Browser other questions tagged

You are not signed in. Login or sign up in order to post.