Vinit Prajapati
Vinit Prajapati

Reputation: 11

Split Comma separated Values in Column MYSQL

Here is My Resultset

    id  cpumanufacturer cpuseries
200014  Intel           Core i7,Core i7 Extreme Edition

200015  Intel           Core i7 Extreme Edition,Core i7

200259  Intel           Core i7 Extreme Edition,Core i7

I want to split cpu series to spanned across multiple rows like for First Row output should be

200014 | Intel | Core i7
200014 | Intel | Core i7 Extreme Edition

Upvotes: 1

Views: 2203

Answers (1)

Gustav Bertram
Gustav Bertram

Reputation: 14911

There is a blog post that describes a stored procedure that will modify your table from this:

id     cpumanufacturer cpuseries

200014 Intel Core      i7,Core i7 Extreme Edition
200015 Intel Core      i7 Extreme Edition,Core i7
200259 Intel Core      i7 Extreme Edition,Core i7

To this:

id     cpumanufacturer cpuseries

200014 Intel           Core i7
200014 Intel           Core i7 Extreme Edition    
200015 Intel           Core i7 Extreme Edition
200015 Intel           Core i7
200259 Intel           Core i7 Extreme Edition
200259 Intel           Core i7

The blog post: http://www.marcogoncalves.com/2011/03/mysql-split-column-string-into-rows/

Keep in mind that this will modify the table, not your query results.

You may also find the following answer useful: https://stackoverflow.com/a/5344071/1005039

Upvotes: 2

Related Questions