Combining multiple text fields into one of MySQL

I have a list of users in a table, with separate fields for first, middle and last name. For various reasons, I need to change the database structure so that there is only one "name" field. What is the best / easiest way to transfer my data from three old fields to one new field?

+3
source share
4 answers

First add a column whose length is greater than all 3 together.

alter table tbl add fullname varchar(100);

Then update it using concat input of old columns.

update tbl set fullname = concat(lastname, ', ', firstname, ' ', middlename)

(It ends in the form of "Kirk, John M")

Then remove the old columns

alter table tbl drop column firstname;
alter table tbl drop column middlename;
alter table tbl drop column lastname;
+4
source
UPDATE Users SET FullName = FirstName + ' ' + MiddleName + ' ' + LastName
+1
source
UPDATE Users SET Fullname = CONCAT(Firstname, " ", MiddleName, " ", LastName);
0

, ' + ' -NULL.

0

All Articles