it's b/c there are 2 rows in each of the tables. If you have an example w/ 3 or 4 rows in one or both of the tables, things will get worse.
What DBMS are you on?
This syntax should work in MS SQL ... MySQL would probably be somewhere close.
Select CC.Total_Price - AC.Total_Price From
(Select sum(total_Price) as Total_Price From customer_cost where job_number = 46) CC,
(Select sum(total_Price) as Total_Price From Actual_cost where job_number = 46) AC
What this does is summarizes before it joins so there is only 1 record on each side to be joined.
Main Topics
Browse All Topics





by: hernst42Posted on 2007-04-20 at 07:34:41ID: 18946699
The duplication is caused by the join. So if have multiple rows in each table with the same id you will need to use subqueries for each part the result you get for your join is:
The resulting table rows are for your example:
46 - 135 - 46 - 101.25
46 - 135 - 46 - 180
46 - 247.50 - 46 - 101.25
46 - 247.50 - 46 - 180