Skip to content
Advertisement

MySQL: Split comma separated list into multiple rows

I have an unnormalized table with a column containing a comma separated list that is a foreign key to another table:

I want to read this data into a search engine that offers no procedural language.

So is there a way to either make a join on this column or run a query on this data that inserts appropriate entries into a new table? The resulting data should look like this:

I could think of a solution if the DBMS supported functions returning a table but MySQL apparently doesn’t.

Advertisement

Answer

In MySQL this can be achieved as below

Now to get the length of comma separated vehicle_ids use below query

For more info visit http://amitbrothers.blogspot.in/2014/03/mysql-split-comma-separated-list-into.html

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement