Velanna
kiwifarms.net
- Joined
- Mar 17, 2021
I'm really sorry if this is in the wrong place.
The gist of this whole thing: how do I split a string in a cell, and insert it into a new row keeping other information with it.
I'm trying to teach myself SQL and I'm currently working on a guided project with this dataset:
I know it's really stupid but I'm stupid as well so I'm starting off with something light so I can learn. Anyway I'm trying to normalize the data. I'm working through 1NF and I'm trying to have it so there is only one fur color per cell in the Highlight Fur Color column. So basically I want to split the two colors in the highlight Fur color and create a new row with the same information except for the highlighted fur color. So basically instead of this:
I want this:
I'm thinking of dropping the combo fur column entirely. I tried using cross apply but I'm using mysql which doesn't support that. So I *think* I need to use a function or a substring index or both. The closest I can find to helping me is this: https://stackoverflow.com/questions/17942508/sql-split-values-to-multiple-rows
I've narrowed it down to either the second part of the top solution (the 'if you cannot create a table') or the JSON solution.
The only problem I'm having is that every solution I come across has them writing a statement for each row, but the dataset I'm using has 3000+ rows which is why I think I need a function, but the JSON version looks easier however I don't know if it will work with the data I'm using. Can anyone dumb this info down for me so I can understand how do this?
The gist of this whole thing: how do I split a string in a cell, and insert it into a new row keeping other information with it.
I'm trying to teach myself SQL and I'm currently working on a guided project with this dataset:
I know it's really stupid but I'm stupid as well so I'm starting off with something light so I can learn. Anyway I'm trying to normalize the data. I'm working through 1NF and I'm trying to have it so there is only one fur color per cell in the Highlight Fur Color column. So basically I want to split the two colors in the highlight Fur color and create a new row with the same information except for the highlighted fur color. So basically instead of this:
id | date | age | primary | highlight |
1 | 10172018 | adult | gray | white |
2 | 10102018 | adult | cinnamon | grey,white |
3 | 10122018 | adult | cinnamon | white |
id | date | age | primary | highlight |
1 | 10172018 | adult | gray | white |
2 | 101020118 | adult | cinnamon | grey |
2 | 10102018 | adult | cinnamon | white |
3 | 10122018 | adult | cinnamon | white |
I'm thinking of dropping the combo fur column entirely. I tried using cross apply but I'm using mysql which doesn't support that. So I *think* I need to use a function or a substring index or both. The closest I can find to helping me is this: https://stackoverflow.com/questions/17942508/sql-split-values-to-multiple-rows
I've narrowed it down to either the second part of the top solution (the 'if you cannot create a table') or the JSON solution.
The only problem I'm having is that every solution I come across has them writing a statement for each row, but the dataset I'm using has 3000+ rows which is why I think I need a function, but the JSON version looks easier however I don't know if it will work with the data I'm using. Can anyone dumb this info down for me so I can understand how do this?