Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Summary two tables

Author  Topic 

lydia
Starting Member

34 Posts

Posted - 2012-03-06 : 06:04:25
I would like to summary table_A and Table_B as below:

Table_A

Field_1 | Field_2 |
--------------------
Mr.A | 100
Mr.B | 300
Mr.C | 150
Mr.D | 400

Table_B

Field_1 | Field_2 |
--------------------
Mr.T | 50
Mr.A | 30
Mr.Y | 80
Mr.B | 90

Result:

Field_1 | Field_2 |
--------------------
Mr.A | 130
Mr.B | 390
Mr.C | 150
Mr.D | 400
Mr.T | 50
Mr.Y | 80

Thanks inadvance :)



khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-03-06 : 06:46:01
[code]
select Field_1, sum(Field_2)
from
(
select Field_1, Field_2 from Table_A
union all
select Field_1, Field_2 from Table_A
) f
group by Field_1
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

lydia
Starting Member

34 Posts

Posted - 2012-03-14 : 03:10:43
Thanks for your help :)
Go to Top of Page
   

- Advertisement -