1
I am trying to join data from three tables using this sql:
select c.NOME,c.CPF,e.DATA_CAD ,e.ENFERECO as ENDEREÇO_Atual , sum(f.VALOR)
from cli1 as c
inner join end1 as e
on c.IDCLI1 = e.ID_END
inner join fat1 as f
on f.ID_FATEND1 = e.IDEND1
where CPF = '12345678912'
order by e.ENFERECO desc;
The problem is that it returns the data with the first registered address, and I wanted to return with the last registered address and the date of change related to it and the total amount invoiced.
How can I proceed in this case?
use
order by e.DATA_CAD desc, e.ENFERECO desc
?– Ricardo Pontual
This form also does not return with the date and the most recent address, returns the first date and address registered with the sum of the invoiced values.
– Dan Mattos
mounts an example with data to make it easier to help. It can be in sqlfiddle
– Ricardo Pontual
Follow the Link sqlfiddle
code
– Dan Mattos