This topic is locked

ERROR (Sum between two tables values are multiplying by the number of records)

11/11/2016 1:00:59 PM
PHPRunner General questions
anderson810311 author

Help me!
I have two tables, one called "rec_lider" and the other as "rec_fiscal", in both I have a column called "CD", I am calculating the amount of received in the two tables, however when I make a "JOIN" in rec_lider.cd = Rec_fiscal.cd, returns me the value much larger than the correct value.
The tables are multiplying the values, as below:
SELECT

rec_lider.cd AS Unidade,

SUM(rec_lider.total_recebido) AS Total Recebido,

SUM(rec_fiscal.total_devolvido) AS Total Auditado

FROM rec_lider

LEFT OUTER JOIN rec_fiscal ON rec_lider.cd = rec_fiscal.cd

GROUP BY rec_lider.cd




Table rec_lider: rec_lider
Table rec_lider: rec_fiscal