0

I have been looking for an example of how this might be done in MySQL-- I really would appreciate the help.

Problem --> Need to split string into two columns based on lower case words (acting as delimiters)

Example, say I have a string in a column that says:

Minnesota Bulls at Nevada

I would want:

Column 1        | Column 2 
--------------------------
Minnesota Bulls | Nevada 

Another Example, say I have:

California Devils playing against the Minnesota Giants

I would want:

Column 1          | Column 2 
------------------------------------
California Devils | Minnesota Giants
  • 1
    Any specific database? ([Oracle solution](https://stackoverflow.com/questions/30704195/how-can-i-use-regex-to-split-a-string-using-a-string-as-a-delimiter)) – GolezTrol Nov 12 '18 at 09:17
  • Hey! Thanks so much! MySQL – Maricela Coronado Nov 12 '18 at 09:19
  • 1
    I don't know how to do it in MySQL, and apparently it's [quite a bit](https://stackoverflow.com/questions/26498939/using-regular-expressions-to-split-one-column-into-multiple-columns) if possible at all. Maybe this needs to be a multi-step process, where you first split the string on spaces, then calculate the index of the item that starts with a lowercase letter, and then `group_concat` the words from before that index and after that index separately to get the original string again. – GolezTrol Nov 12 '18 at 09:23
  • You may look into using `REGEXP_REPLACE`, if you're using MySQL 8 or later. – Tim Biegeleisen Nov 12 '18 at 09:26
  • And of course, if this is for display somewhere, you could do the heavy lifting in your database client (for instance a PHP script), instead of in the query itself. – GolezTrol Nov 12 '18 at 09:58

0 Answers0