I've got a table with multiple duplicated entries in a column and I want to put these entries in a new table and connect these tables with a foreign key in the initial table.
Old Table:
table 1
| id | name | medium |
|  0 | xy   |  a     |
|  1 | xz   |  b     |
|  2 | yz   |  a     |
new Table:
table 1                               table2
| id | name | medium |               | id | name |
|  0 | xy   |  0     |               | 0  | a    |
|  1 | xz   |  1     |               | 1  | b    |
|  2 | yz   |  0     |
With CREATE ... SELECT I have a good tool to create a new table from the results of a query but I don't know how to change the entries from table1.medium to a foreign key based on the comparison to table2.medium. Is there any chance to do that?
 
     
     
     
    