mysql - Splitting name column with multiple delimiters -


i'm trying split name column (fullname) format lastname, firstname 2 separate columns in mysql using:

select substring_index(substring_index(fullname, ',', 1), ' ', -1) firstname, substring_index(substring_index(fullname, ',', 2), ' ', -1) lastname tablename; 

this works on most names. however, name "del torres jr, marcelo" shows

-------------------- lastname | firstname --------------------    jr       | marcelo   -------------------- 

how need alter statement capture of name after comma?

can not use:

select substring_index(fullname, ',',  1) firstname        ,substring_index(fullname, ',', -1) lastname table 

sqlfiddle

i can't tell you're trying match against ' ' if you're trying trim whitespace can use trim() on values.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -