troubleshooting Question

MySQL made multiple rows from delimited field

Avatar of Tony Pearce
Tony PearceFlag for United Kingdom of Great Britain and Northern Ireland asked on
MySQL Server
4 Comments1 Solution450 ViewsLast Modified:
I dont know if this is possible, I have data in the format:

code                subcode         ref      price      stock                  variants
SKU16927      SKU16927      0      51.01      1000                  colour=black/blue;size=S
SKU16927      SKU169270      0      51.01      1000                  size=S;colour=grey/white
SKU16927      SKU169271      0      51.01      1000                  size=M;colour=black/blue
SKU16927      SKU1692702      0      51.01      1000                  colour=grey/white;size=M
SKU16927      SKU169272      0      51.01      1000                  size=L;colour=black/blue
SKU16927      SKU1692703      0      51.01      1000                  size=L;colour=grey/white
SKU16927      SKU169274      0      51.01      1000                  size=XL;colour=black/blue

As you can see the last column contains two sets of data, (in this example size and colour but this field could contain more than shown) what I want to do is create the result below:

code                subcode         ref      price      stock                  variants
SKU16927      SKU16927      0      51.01      1000                  colour=black/blue
SKU16927      SKU169270      0      51.01      1000                  colour=grey/white
SKU16927      SKU169270      0      51.01      1000                  size=S

but only distinct 'variants' for main 'code' the 'subcode' is not important.

Any ideas??
Lee Wadwell
Project Architect

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros