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
 Merge data

Author  Topic 

archanasql
Starting Member

27 Posts

Posted - 2008-07-29 : 11:07:00
Hi ,

I have two tables with some data.I would like to add the data of a common column to a new table..

table 1

1 abc 6000
2 xyz 3000

table 2

1 abc 4000
2 xyz 2000

I want output into new table TABLE3 by merging the above two tables

Table3
1 abc 10000
2 xyz 5000

kindly let me the know the query..

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-29 : 11:14:07
[code]INSERT INTO table3(field1,field2,field3)
SELECT field1,field2,SUM(field3) AS field3
FROM
(
SELECT field1,field2,field3
FROM table 1
UNION ALL
SELECT field1,field2,field3
FROM table 2
)t
GROUP BY field1,field2[/code]
Go to Top of Page
   

- Advertisement -