MS-SQL: Combining two identical tables, eliminate duplicate rows, SUM one column???
Posted on 2004-09-08
I have two identically structured tables. The data is different however, for one is a 'temp' table that is continually feed new data and the other is a 'result' table which is connected to a C# ListView. As you might have guessed, I need the 'temp' table to periodically add its data to the 'result' table to have a current SUM of all my data. It was too taxing on the ListVeiw to read from the same table the live data was feeding to, so I have two tables.
If I use a UNION like so, I end up with ALL the data from both tables displayed seperately row by row, no adding or SUM taking place.
Table Structure: First column is PRIKEY (INT 4), next four data columns (VARCHAR 50), last data column named 'counted' (INT 4).
Q. How do I combine two identically structured tables, eliminate dulplicate rows and SUM the last column 'counted'???
--select * from temp
--select * from result