Plipus Tel
Plipus Tel

Reputation: 755

Merging Duplicate Records From Two Tables Into One Table

I have two tables as describe bellow:

enter image description here

How can I perform a query to merge the duplicate data in table B, so I can get table C in which the records derived from table A and Table B?

Any help will by highly appreciated.. Thank You !

Upvotes: 1

Views: 173

Answers (1)

John Woo
John Woo

Reputation: 263693

This can be done using UNION

SELECT ID, Value FROM TableA
UNION
SELECT ID, Value FROM TableB

if there is an extra table named TableC and you want to insert the result of TableA and TableB, use INSERT INTO...SELECT statement,

INSERT INTO TableC(ID, Value)
SELECT ID, Value FROM TableA
UNION
SELECT ID, Value FROM TableB

Or maybe you want to create a VIEW

CREATE VIEW TableC
AS
SELECT ID, Value FROM TableA
UNION
SELECT ID, Value FROM TableB

to call the View,

SELECT * FROM TableC

Upvotes: 1

Related Questions