'mysql query that splits string for an Insert?
I got a customers
table with this column: hashtag VARCHAR(255)
, that contains lowercase words separated by white spaces.
We added a new table:
hashtag ( id INT, tag VARCHAR(255) )
I need to take each customer's hashtag string, split it, and insert it in the hashtag table if it doesn't exists.
I'd really prefer to do everything SQL only and write php if it's inevitable.
Does MySQL permit to split a string column at each occurrence of a certain char and use the resulting words to execute an insert?
Solution 1:[1]
INSERT INTO hashtag
(tag)
SELECT *
FROM String_split ((SELECT hashtag
FROM customers), ' ')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | RF1991 |