0

Here is how columns look like in my table:

VID | UID | title | description | featuredesc | keyword | ...

I would like to copy all "title" rows and turn them to keywords format in "keyword" rows.

title: This Is An Example Just For You

To

keyword: This,Is,An,Example,Just,For,You

And Also, I am trying to find a way to exclude the keywords that have less than 3 characters.

I Just need to keep Lowercase or Uppercase as it is.

keyword: This,Example,Just

It's not gonna be perfect but I want to make tag selection as clean as possible. Only from titles data.

I've been trying to write this SQL Query for a while but without success.

Hope to find help here.

Thanks.

ben
  • 31
  • 4
  • You shouldn't use comma-separated values. Create another table with each tag in its own row, and use a foreign key to relate them to the main table. – Barmar Feb 04 '21 at 19:38
  • There's no easy way to split lists in MySQL. – Barmar Feb 04 '21 at 19:39
  • See https://stackoverflow.com/questions/17942508/sql-split-values-to-multiple-rows – Barmar Feb 04 '21 at 19:40
  • @Barmar The CMS I am using needs comma-separated tags in the database to show up properly on frontend. – ben Feb 04 '21 at 19:47

1 Answers1

0

Converting 'This Is An Example Just For You' to 'This,Is,An,Example,Just,For,You' is easy. You can achieve this through below query. I will edit my answer with second solution shortly.

update tableName set keyword=replace(title,' ',',')