0

I have the following:

Is this possible by sql query in MYSQL DB? Or need php after result? thanks

name | date

test1 | 2019-01-01,2019-02-02,2019-03-03,2019-03-03

test2 | 2019-04-01,2019-05-01,2019-06-01,2019-07-01

And like to get:

name | date | 

test1 | 2019-01-01 |
test1 | 2019-02-02 |
test1 | 2019-03-03 |
test1 | 2019-03-03 |
test2 | 2019-04-01 |
test2 | 2019-05-01 |
test2 | 2019-06-01 |
test2 | 2019-07-01 |
jarlh
  • 40,041
  • 8
  • 39
  • 58
Hocus
  • 3
  • 2
  • 5
    I would recommend handling this in PHP. But, I would even more strongly recommend _against_ storing CSV in your MySQL tables this way. It will only cause you problems later on. – Tim Biegeleisen Apr 15 '19 at 10:38
  • 1
    See also https://stackoverflow.com/questions/17308669/what-is-the-opposite-of-group-concat-in-mysql – Maxim Krizhanovsky Apr 15 '19 at 11:33

1 Answers1

0

for this particular case you can give in hardcoded values:

select m.* from(select name,substring(date,1,10) as str
from table1
union all
select name,substring(date,12,10) as str
from table1
union all
select name,substring(date,23,10) as str
from table1
union all
select name,substring(date,34,10) as str
from table1)m order by m.name;

https://www.db-fiddle.com/f/xcRVMVV5qeh7J2BK1zMP4E/0

nikhil sugandh
  • 3,422
  • 4
  • 16
  • 29