sql sum data from multiple tables

Posted by Iulian on Stack Overflow See other posts from Stack Overflow or by Iulian
Published on 2010-04-07T09:49:24Z Indexed on 2010/04/07 9:53 UTC
Read the original article Hit count: 459

Filed under:
|
|

I have 2 tables AP and INV where both have the columns [PROJECT] and [Value].

I want a query to return something like this :

PROJECT | SUM_AP | SUM_INV

I came up with the code below but it's returning the wrong results ( sum is wrong ).

SELECT SUM(AP.Value) AS SUM_AP, 
SUM(INV.Value) AS SUM_INV
FROM AP INNER JOIN INV ON (AP.[PROJECT] =INV.[PROJECT])
WHERE AP.[PROJECT] = 'XXXXX'
GROUP BY AP.[PROJECT]

© Stack Overflow or respective owner

Related posts about sql

Related posts about ms-jet-ace