SQL - sum columns with same name from diferent tables I have 3 Tables:



_tbl1_____
ID  C1  C2
--  --  -- 
AA   2   3
BB  10  12
CC  20  22

_tbl2_____
ID  C1  C2
--  --  -- 
BB  10  12
AA   2   3
CC  20  22

_tbl3_____
ID  C1  C2
--  --  -- 
AA   0   0
BB  10  12
HH  55  66



and I want sum the columns with same name and rows with same id
to get a result like this:



Query result tbl
ID  C1  C2
--  --  -- 
AA   4   6
BB  30  36
CC  40  44
HH  55  66



Thank you guys for your help.. I really need it.
If they're all in the same order, you can do it easily like this,

SELECT t.id, sum(c1), sum(c2)
FROM (
  SELECT *
  FROM tbl1
  UNION ALL ( TABLE tbl2 )
  UNION ALL ( TABLE tbl3 )
) AS t
GROUP BY t.id
ORDER BY 1;


If they're in different orders just replace TABLE tbl2 with SELECT id, c1, c2 FROM tbl2 (they're the same thing).