vbNewbie
vbNewbie

Reputation: 3345

merge two tables into one

I would like join two tables into 1 table that has one common column and I need to try and avoid all duplicates.

Upvotes: 1

Views: 4876

Answers (4)

user3868077
user3868077

Reputation: 11

Hope this will help

MERGE <target_table> [AS TARGET]
USING <table_source> [AS SOURCE]
ON <search_condition>
[WHEN MATCHED 
THEN <merge_matched> ]
[WHEN NOT MATCHED [BY TARGET]
THEN <merge_not_matched> ]
[WHEN NOT MATCHED BY SOURCE
THEN <merge_ matched> ];

Upvotes: 0

KM.
KM.

Reputation: 103587

look at this (new in SQL Server 2008): MERGE (Transact-SQL)

Performs insert, update, or delete operations on a target table based on the results of a join with a source table. For example, you can synchronize two tables by inserting, updating, or deleting rows in one table based on differences found in the other table.

Upvotes: 2

Raj More
Raj More

Reputation: 48016

You can do a UNION and insert into the new table (note that you have to create the table first)

INSERT INTO NewTable

SELECT Column1
FROM FistTable

UNION 

SELECT Column2
FROM SecondTable

Upvotes: 0

Malfist
Malfist

Reputation: 31795

Perhaps you want a SELECT DISTINCT and a LEFT JOIN

Upvotes: 0

Related Questions