-1

Usernames are stored in a DB in one column, how I can divide this column on first name and last names columns.

I am thinking about create a loop and run through fullname column split first name and second name by space and store them in corresponding columns. But where do I have to create this loop?

Pete
  • 57,112
  • 28
  • 117
  • 166
qr11
  • 443
  • 2
  • 5
  • 25

1 Answers1

0

You can use SPLIT_STR function . Assuming each username has 2 words splitted with a space.

DB::query(
"INSERT INTO tables (firstname,lastname)
 SELECT SPLIT_STR(username, ' ', 1),SPLIT_STR(username, ' ', 2) FROM oldusers "
);   
Abdou Tahiri
  • 4,338
  • 5
  • 25
  • 38