Forum Moderators: coopster

Message Too Old, No Replies

MySQL, group_concat

merging data together

         

someone

7:54 pm on Jan 12, 2006 (gmt 0)

10+ Year Member



I posted this message before.

I have a couple thousand rows of data like this:


Book_num Title Price Category Abstract
b158 PHP 5 101 PHP is cool
b158 PHP 5 203 PHP is cool
b158 PHP 5 309 PHP is cool
c201 C+ 10 102 Learn C+
c201 C+ 10 212 Learn C+
C201 C+ 10 366 Learn C+

With the suggestion of some experts here, I was able to merge the different Category data into one column and just have one row of each Book_num using Mysql's GROUP_CONCAT.


Book_num Title Price Category Abstract
b158 PHP 5 101,203,309 PHP is cool
c201 C+ 10 102,212,366 Learn C+

This worked fine. But now, I need to do something like this and I am not sure how to start it.


Book_num Title Price Category1 Category2 Category 3 Abstract
b158 PHP 5 101 203 309 PHP is cool
c201 C+ 10 102 212 366 Learn C+

So instead of merging the catagory into one column, I want one each of them to have its own column, category1, category2, category3.

Sorry the alignment looks awfule on screen.

jatar_k

8:04 pm on Jan 12, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



one option would be to

create a new table
select row from old table using php
split column to build new insert query
insert new row into new table

would work, a couple thousand rows wouldn't take long