Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Append all matching records from one table to Another

$
0
0

I have 2 tables, which are listed below.

-tblMAIN 

-tblAdditions

tblMain contains all the data and tblAdditions contains unique types. These tables are joined together by the common field "LinkID". 

I'll supply a scenario here. Let's say that tblMain contains Types (A, B, and C). I need the rows of data for A, B, and C from tblAdditions to be inserted into tblMain. It does not matter how many total records there are for each type in tblMain. I just need one of each type inserted into the table. 

I know how I could go about doing this making a temp table of the distinct Types in tblMain and then creating SQL that would join that table to tblAdditions and insert the records that way, which would produce the desired results of inserting a total of 3 records but I know that's not the most efficient way of doing it. I'm imagining that this can be done with some sort've subquery, I just need a little guidance on how to do it. Any assistance would be appreciated. Thanks.


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>