CONCAT function in SQL

In SQL, the CONCAT function is used to combine two or more strings into a single string.

Example:

SQL

CREATE TABLE Employees (
   EmployeeID INT,
    FirstName VARCHAR(20),
    LastName VARCHAR(20),
    Age int
); 

Insert the data in the Employees table.

SQL

insert into Employees values
(1, "Ashish", “Goel", 25), 
(2, "Kirshan", "Gupta", 30),
(3, "Anjali", "Sharma", 25),
(4, "Manju", "Saini", 15),
(5, "Katrina", "Kaif", 18),
(6, "Esha", "Dixit", 20),
(7, "Ankita", "Verma", 19), 
(8, "Meenakshi", "Chikkara", 35),
(10, "Alia", "Bhatt", 16);  

By using the Create table and insert statement we reach to the following table in our database:

Table: Employees

EmployeeIDFirst NameLast NameAge
1AshishGoel25
2KirshanGupta30
3AnjaliSharma25
4ManjuSaini15
5KatrinaKaif18
6EshaDixit20
7AnkitaVerma19
8MeenakshiChikkara35
10AliaBhatt16

Use the CONCAT() function to concatenate the firstname and last name.

SQL

SELECT 
    EmployeeID, 
    FirstName, 
    LastName, 
    CONCAT(firstname, “ ”, lastname) AS FullName
FROM Employees; 

The output of the above query is shown below:

EmployeeIDFirst NameLast NameFull Name
1AshishGoelAshish Goel
2KirshanGuptaKirshan Gupta
3AnjaliSharmaAnjali Sharma
4ManjuSainiManju Saini
5KatrinaKaifKatrina Kaif
6EshaDixitEsha Dixit
7AnkitaVermaAnkita Verma
8MeenakshiChikkaraMeenakshi Chikkara
10AliaBhattAlia Bhatt