0

Hello i want to split a resulting column in multiple columns just like on the link. But number of columns are not specific ;

Example

COL1                 |   OTHER COLUMNS
----------------------------------------
this,will,split      | some value
also,this            | some value
this,is,four,columns | some value

I want make this something like that ;

COL1 | COL2 | COL3 | COL4   | OTHER
----------------------------------------
this | will | split| NULL   | some value
also | this | NULL | NULL   | some value
this | is   | four | columns| some value

edit

it looks like similar that question but not:

Can you split/explode a field in a MySQL query?

I want results in 1 row, I dont want something like that;

RESULT
-----
this
will
split
...

on that question you can see there is specific number of cols. bu i dont. :(

How to split a resulting column in multiple columns

Community
  • 1
  • 1
arikanmstf
  • 462
  • 7
  • 16
  • Possible duplicate of [Can you split/explode a field in a MySQL query?](http://stackoverflow.com/questions/471914/can-you-split-explode-a-field-in-a-mysql-query) – Seth McClaine Mar 11 '16 at 15:36
  • my problem is split column, but it is not certain how many columns should be created – arikanmstf Mar 11 '16 at 15:53

1 Answers1

0

I think you can create one relational table and add multiple entry in relational table, hear you don't need to think about column, you have to add entry in row.

eg.



Table 1:

ID | COL1                 |   OTHER COLUMNS
----------------------------------------
1  |this,will,split      | some value
2  |also,this            | some value
3  |this,is,four,columns | some value

Table2
ID | Table1_id | value
-------------------------
1  | 1         | this
2  | 1         | will
3  | 1         | split
4  | 2         | also
5  | 2         | this
6  | 3         | this
6  | 3         | is
6  | 3         | four
6  | 3         | columns 

Please check this, i think fix your problem.

  • actually that comes from relational table , I concat that rows into one row with "," first. it is something like , writer_1 , writer_2 , writer_3 ..... of a book. my writer-book table like => writer_id - book_id. even if I dont concat that table , how can I make this rows to column ? – arikanmstf Mar 14 '16 at 10:47