Reputation: 102
I m new to SQL Server, please help me with the solution to following problem.
I have two tables which have the following columns:
Table-A
only has one column with data like (A, B, C, D
)Table-B
is a temporary table which can contain (B, B, C, C, E, E, F, G
)I need to insert contents of table B into table A.
Conditions are
How can I possibly solve this problem?
Thanking you in advance....
Upvotes: 0
Views: 113
Reputation: 3137
Try this....
INSERT INTO Table (Column)
SELECT DISTINCT tt.Column
FROM TempTab tt
WHERE tt.Column NOT IN (SELECT DISTINCT Column FROM Table)
Here is the SQL FIDDLE with this query.
Upvotes: 2
Reputation: 4584
INSERT INTO A(col)
(SELECT distinct col from B
minus
(SELECT distinct col FROM A INTERSECT SELECT distinct col FROM B))
Upvotes: 1