List:General Discussion« Previous MessageNext Message »
From:Wesley Furgiuele Date:September 8 2004 2:53pm
Subject:Re: Substring functions in mySQL
View as plain text  
Assuming there are no parts of a name that include more than one word
(e.g., "Mary Jo" being someone's first name), an easy way would be to
use SUBSTRING_INDEX.

First Name = SUBSTRING_INDEX( namefield, ' ', 1 );
Middle Name = SUBSTRING_INDEX( SUBSTRING_INDEX( namefield, ' ', 2 ), ' ', -1 );
Last Name = SUBSTRING_INDEX ( namefield, ' ', -1 );

http://dev.mysql.com/doc/mysql/en/String_functions.html

Wes



On Wed, 08 Sep 2004 13:35:07 +0000, wally.randall@stripped
<wally.randall@stripped> wrote:
> How can I extract a middle segment of text in mySQL.  For example a column contains
> this string: 'William Walker Jones'.  I need to split this into the first, middle, and
> last names.  I can easily extract the first and last names but how do I extract the Middle
> name?
>
Thread
Substring functions in mySQLwally.randall8 Sep
  • Re: Substring functions in mySQLWesley Furgiuele8 Sep
  • Re: Substring functions in mySQLSGreen8 Sep