1

i have table in the following format

**id   mobile  landline**
x1   2,3,4   17,18
x2   4,5,6
x3   7,8,9   19

trying to insert the data in a table in the following table.

**id  mobile  landline**
x1  2       17
x1  3       18
x1  4

Please help.

roeygol
  • 4,908
  • 9
  • 51
  • 88
Rahul Singh
  • 918
  • 14
  • 31
  • Always 3 numbers? What are their range? – sagi Nov 01 '16 at 13:19
  • there can be any range it is just an example. – Rahul Singh Nov 01 '16 at 13:20
  • To the best of my recollection, there is no `split` function in MySQL. You may wish to develop one of your own (or google; I recall seeing many examples, though no recollection of MySQL specific). – FDavidov Nov 01 '16 at 13:26
  • This isn't going to be a one-step operation. Do you have to have an ongoing process for new data, or is this a one-time operation? – CLAbeel Nov 01 '16 at 13:27

1 Answers1

1

Is the end table structure negotiable? Might I propose:

id  type    value
x1  mobile  2
x1  mobile  3
x1  mobile  4
x1  landline  17
x1  landline  18

or if you have to go with columns for landline and mobile:

id  mobile  landline**
x1  2       <null>
x1  3       <null>
x1  4       <null>
x1  <null>  17       
x1  <null>  18

Otherwise it appears that landline 17 is associated with mobile 2, which isn't implied in the source table.

Once you've decided that, check out Split comma separated value from table column into rows using mysql? and see if you can apply that solution.

Community
  • 1
  • 1
CLAbeel
  • 1,078
  • 14
  • 20