![](/img/trans.png)
[英]Different structure names but same structure variables - How to make each structure variable unique?
[英]how to merge different tables that have the same structure in mysql?
I want to merge two or more tables in to one, for example, I have table1.csv and table2.csv, they are from different Mysql server but have the same structure like [A, B, C, datatime].
對於不同的記錄,如果A、B、C的值不一樣,那么直接當作不同的記錄,如果A、B、C的值相同,那么只有datatime最新的記錄保留。
如果我先用程序把select哪些記錄在本地有用,然后一起插入到mysql中,會不會比邊選擇邊一個一個插入快?
您可以在要插入的表上的三個字段上使用復合唯一鍵輕松完成
此查詢將添加一個唯一鍵,因此您可以再次添加同一行
ALTER TABLE `table1` ADD UNIQUE `unique_index`(`a`, `b`, `c`);
此查詢將 append 只有不同的記錄
INSERT IGNORE table1 SELECT * FROM table2
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.