Database I created 15 years ago was not well designed. I have a varchar column with a string of comma delimited values: '5,8,13'. The string contains no spaces and no trailing commas but the number of values are variable. What I'd like to do is create a new table and move these values into it paired with that row's ID. Assume the above values are from a row with an ID of 7, the result would be 3 rows:
[
{7, 5}
{7, 8}
{7, 13}
]
Looking at the existing data set, the column has anywhere from 1 to 6 values. I found this thread showing how I could do a split string function: Split value from one field to two
But frankly, I'm at a loss on how I'd go about turning this into a single insert. If it's not a simple task, then I'll just write something in PHP even though it'll be a lot of insert statements.
Further explanation, here are two tables:
create table Table_A(
id int auto_increment primary key,
platforms varchar(255)
)
create table Table_B(
id int auto_increment primary key,
platform int not null
)
Table_A is the existing data where the data in platforms column is a comma separated value of numbers "3,45," or "56,4". These numbers point to indexes in another table. yes I know poor design, thankfully I've learned better since those days. I want to parse the numbers from the platform string in Table_A and insert them into Table_B along with the ID of said Table_A row.