I would like merge 2 MySQL tables without adding the same lines.
I have 2 tables with the sames columns but not the same row, such as.
table_1
+-------+--------+------+
| Name | ResNum | Code |
+-------+--------+------+
| User1 | 25BAM8 | PAR1 |
| User2 | E26J09 | COP3 |
+-------+--------+------+
table_2
+-------+--------+------+
| Name | ResNum | Code |
+-------+--------+------+
| User1 | 25BAM8 | PAR1 |
| User3 | 34VNS2 | PAR1 |
| User4 | EZQVG5 | COP3 |
+-------+--------+------+
I want when merging table_2 to table_1, got this:
table_1
+-------+--------+------+
| Name | ResNum | Code |
+-------+--------+------+
| User1 | 25BAM8 | PAR1 |
| User2 | E26J09 | COP3 |
| User3 | 34VNS2 | PAR1 |
| User4 | EZQVG5 | COP3 |
+-------+--------+------+
I have already tried with INSERT IGNORE INTO and REPLACE INTO command but it copy the existing rows, like that:
table_1
+-------+--------+------+
| Name | ResNum | Code |
+-------+--------+------+
| User1 | 25BAM8 | PAR1 |
| User1 | 25BAM8 | PAR1 |
| User2 | E26J09 | COP3 |
| User3 | 34VNS2 | PAR1 |
| User4 | EZQVG5 | COP3 |
+-------+--------+------+
Any help would be appreciated.
An easy solution would be to put a temporary UNIQUE index on Name on table_1:
To transfer the actual rows, use a SELECT INSERT:
Then drop the UNIQUE index: