How to append data from one table in another where both table structure is same

Actually both tables are the same, and I just need to merge data.

INSERT INTO table1
SELECT * FROM table2
WHERE id NOT IN (select id from table1);

if id is primary key

INSERT INTO table1(f1,f2,f3)
SELECT f1,f2,f3 FROM table2
WHERE id NOT IN (select id from table1);
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s