Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6743717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:59:41+00:00 2026-05-26T11:59:41+00:00

I have a table which contains rows, within each row there is a field

  • 0

I have a table which contains rows, within each row there is a field which contains peoples names seperated by a double space.

I need to extract this field from each row, then split the field into separate names and dump into another table.

What’s the best way to do this? Do I split it within the sql query or extract the fields then split using PHP?

New info:

OK, the field contains full names e.g. john doe, tom smith etc etc the double spaces separate the full names e.g.

JOHN DOE  TOM SMITH  JOHN WOO

There might be one name in the field but there could also be potentialy up to 10

Thanks

Darren

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:59:42+00:00Added an answer on May 26, 2026 at 11:59 am

    you can do it in sql. should be something like this:

    INSERT INTO tbl_dest (first_name, last_name) VALUES
    
    (SELECT
        LEFT(ts.name, LOCATE('  ',ts.name)) AS first_name,
        SUBSTRING(ts.name, LOCATE('  ',ts.name)+2) AS last_name
    FROM tbl_source AS ts)
    

    as @Marc B stated, it will only work if the data is consistent (ie each row’s name field contains a double space and the first double space separates the name and password.
    you can ignore other rows (without the double space) by simply adding

    INSERT ...
    (SELECT   ... 
    FROM tbl_source AS ts WHERE LOCATE('  ', ts.name) > 0)
    

    if the field starts with a double space (ie first name is empty) it will also be ignored

    EDIT:

    since you said that each row can contain multiple pairs of first/last name. here’s a code example:

    $query = "SELECT `name` FROM `tbl_source`";
    $res = mysql_query($query, $link);
    $names = array();
    while ($row = mysql_fetch_assoc($res)) {
        $nmlist = explode('  ',$row['name']);
        for($i=0, $n=count($nmlist); $i<$n-1; $i+=2){
            $names[] = "('" . mysql_real_escape_string(stripslashes($nmlist[$i])) ."',"
                       ."'" . mysql_real_escape_string(stripslashes($nmlist[$i+1])) ."')";
        }
    }
    $insert_query = "INSERT INTO `tbl_dest` (`first_name`,`last_name`) VALUES "
              .implode(',', $names);
    mysql_query($insert_query, $link);
    

    in this example, double spaces are between first name and last name, and between each pair

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, I have a table which contains multiple rows. Each row contains some data
I have a mySQL table which contains rows based on payments. Each row contains
In a SQL server database, I have a table which contains a TEXT field
I have a table with multiple tbody's, each of which has a classed row,
I have a table which already contains some rows and does not have a
I have got a table which contains 5 column and query requirements: update row
I have a table which contains a bunch of rows and a sort_order .
We have a (currently InnoDB) table which contains roughly 500,000 rows. This represents a
I have a table row which contains a textbox and it has an onclick
I have table which contains the rows that are dynamic from server side scripting(PHP)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.