SQL Server 2008 r2
I have 2 tables
Table 1
Col1 Col2 Col3 Col4
123 08 1 1
123 08 1 1
123 08 2 1
Table 2
Col1 Col2 Col3
123 08 6
Table 1 is the main column so most of the data comes from this table and it must be a LEFT OUTER JOIN on to Table2 because Table1 has values(col1, col2) that dont always return values in TABLE2 and should appear as NULLS.
My query is
SELECT
a.Col2,
SUM(a.Col3),
SUM(a.Col4),
SUM(b.Col3)
FROM
Table 1 a
LEFT OUTER JOIN Table2 b
ON a.col1 = b.col1 AND a.col2 = b.col2
GROUP BY a.Col2
This would return 08, 4, 3, 18
I would want this to return 08, 4, 3, 6
Because Table 2 joins on 3 rows it then triples the SUM value for b.Col3
What would be the best solution?