For this, use CONCAT() method in MySQL. Let us first create a table −
mysql> create table DemoTable ( FirstName varchar(50), LastName varchar(50) ); Query OK, 0 rows affected (0.63 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Chris','Brown'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('David','Miller'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('John','Doe'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable values('Adam','Smith'); Query OK, 1 row affected (0.25 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-----------+----------+ | FirstName | LastName | +-----------+----------+ | Chris | Brown | | David | Miller | | John | Doe | | Adam | Smith | +-----------+----------+ 4 rows in set (0.00 sec)
Following is the query to concatenate first name and last name to full name −
mysql> select concat(FirstName,' ',LastName) AS FullName from DemoTable;
This will produce the following output −
+--------------+ | FullName | +--------------+ | Chris Brown | | David Miller | | John Doe | | Adam Smith | +--------------+ 4 rows in set (0.00 sec)