开发者

How do I merge two tables in single database?

开发者 https://www.devze.com 2023-02-03 22:47 出处:网络
I do have two table say table1 and table2 both tables have same structure but pk index values are different. so repetation is minimum.

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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消