I've 4 tables
TABLE A_Master
-------------------------
IdA
TABLE A_Detail
------------------------
IdA
Units
TABLE B_Master
--------------------------
IdB
IdA
TABLE B_Detail
------------------------
IdB
Units
AND, I need to select then rows of A where the sum of items of A
(A_Detail.Unit) are diferent of all the sum of items of B (B_Detail.Unit)
that are linked to A (B_Master.IdA = A_Master.IdA)
I do
SELECT MA.IdA, SUM(DA.Items),SUM(DB.Items)
FROM Master_A MA
JOIN Detail_A DA ON DA.IdA = MA.Ida
JOIN Master_B MB ON MB.Ida = MA.IdA
JOIN Detail_B DB ON DB.IdB = MB.IdB
GROUP BY MA.IdA
HAVING SUM(DA.Items)<>SUM(DB.Items)
but don't work, It return bad results
Please, help....