mathew
mathew

Reputation: 11

How do I merge two tables in single database?

I do have two table say table1 and table2 both tables have same structure but pk index values are different. so repetation is minimum.

table1 has got 56000 datas

table2 has got 23000 datas

I want merge/import table2 to table1. there may be some repetations in PK so I need to ignore that data(dont want to import/rewrite or duplicate) and import rest of the data. I am using phpmyadmin so I want do it through that.

Upvotes: 1

Views: 3354

Answers (2)

Ciaran Archer
Ciaran Archer

Reputation: 12466

Have you tried using UNION DISTINCT into another table?

http://dev.mysql.com/doc/refman/5.0/en/union.html

So you could write something like this:

insert into table3
select * from table1 
union distinct 
select * from table2

Hope that helps.

Sorry if syntax is not spot on - don't use MySQL here in work.

Upvotes: 0

Spiny Norman
Spiny Norman

Reputation: 8347

I'm pretty sure you can do:

INSERT IGNORE INTO table1 SELECT * FROM table2;

to ignore duplicate keys.

However, please try it on a third table first ;)

Here's a link: http://dev.mysql.com/doc/refman/5.0/en/insert-select.html

Upvotes: 6

Related Questions