G
G
ganbatte2020-06-02 16:21:18
MySQL
ganbatte, 2020-06-02 16:21:18

How to turn such text (text1, text2, text3) into a column in mysql?

Whether it is possible to make somehow SELECT that the text would appear columns, type.
select (text1, text2, text3) as text;
and what would be like this
|text|
|text1|
|text2|
|text3|

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lazy @BojackHorseman MySQL, 2020-06-02
Tag

can

create table Test(id integer, title varchar(100));
insert into Test(id, title) values(1, "text1,text2,text3,text4");
insert into Test(id, title) values(2, "text5,text6,text7,text8");

select t.id, t.title, iter.c,
SUBSTRING_INDEX(SUBSTRING_INDEX(t.title, ',', iter.c), ',', -1)
from  Test t
JOIN (SELECT 1 AS c UNION SELECT 2 UNION SELECT 3 UNION SELECT 4) iter ON 1 = 1
ORDER BY t.id, iter.c;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question