I need to:
- Join table1 and table2
- Eliminate duplicates
- Keep the originals from table1
- A dictionary to say which was the id in the old table and which is the new id
Example: The output would be something like this
PS: Thing is, table1 originates from an already in production database, and the id I have here is used in many other tables so I CAN'T change what's already on it, only add the new data that's not already on it. But I will also need to say what's the new id of the data.
table1
id name birthdate
1 Goku 1997-12-15
2 Freeza 2000-10-03
3 Vegeta 2003-08-19
table2
id name birthdate
1 Krillin 1983-02-28
2 Roshi 1960-06-07
3 Goku 1997-12-15
4 Freeza 1998-10-10
So what I need to generate from this are the following
resulting_table1
id name birthdate
1 Goku 1997-12-15
2 Freeza 2000-10-03
3 Vegeta 2003-08-19
4 Krillin 1983-02-28
5 Roshi 1960-06-07
6 Freeza 1998-10-10
but I also need a table that says which code a person was on the old table, and which is the new code, which would also, something like that:
from_to_table
id origin new_id
1 table_1 1
2 table_1 2
3 table_1 3
1 table_2 4
2 table_2 5
3 table_2 1
4 table_2 6
I have tried many methods and the only one I got to work now was doing the insertion row by row and doing the checking on the two fields each time, but that just takes way too much time making it not viable.
So far the best way I found consists basically in: Joining the two tables -> Grouping the data and generating new id column -> join the grouped table with the joined two tables to create the from_to_table problem is, that approach will change the ids I must not change, and I don't know how to keep those.