'Normalize many-to-many data
I have a non-normalized database that establishes a many-to-many relationship this way.
Article table:
| id | category_ids | some_more_columns |
| --- | ------------ | ----------------- |
| 1 | [] | |
| 2 | [1, 2] | |
| 3 | [3] | |
Category table:
| id | some_more_columns |
| --- | ----------------- |
| 1 | |
| 2 | |
| 3 | |
I want to make a proper many-to-many relationship like:
Article table:
| id | some_more_columns |
| --- | ----------------- |
| 1 | |
| 2 | |
| 3 | |
Category table:
| id | some_more_columns |
| --- | ----------------- |
| 1 | |
| 2 | |
| 3 | |
Finally, Article has categories table:
| id | article_id | category_id |
| --- | ---------- | ----------- |
| 1 | 2 | 1 |
| 2 | 2 | 2 |
| 3 | 3 | 3 |
I want to write a script to populate the table of Article_has_categories using the column of category_ids in the Article table in MySQL. I'm very young in SQL, so this is very overwhelming. Please shine some light!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
