SQL CONCAT, Concatenate Function

SQL CONCAT Function is used to Concatenate (combine) 2 or more strings. Different databases have different writtings:

SQL Server +
Oracle CONCAT(), ||
MySQL CONCAT()

SQL CONCAT Function Syntax

CONCAT(string1, string2, string3, ...)

Note: In Oracle, the CONCAT function can only take 2 arguments, but || can take more than 2 arguments.

SQL CONCAT Function Example

Table: Employees

EmployeeId FirstName LastName
1 Mazojys Fxoj
2 Jozzh Lnanyo
3 Syllauu Dfaafk
4 Gecrrcc Srlkrt
5 Jssme Bdnaa
6 Dnnaao Errllov
7 Tyoysww Osk

Select EmployeeId, combine FirstName and LastName as FullName from the Employees table:

Example 1, SQL Server

SELECT EmployeeId, FirstName + ' ' + LastName AS FullName
FROM Employees

Example 2, Oracle

SELECT EmployeeId, FirstName || ' ' || LastName AS FullName
FROM Employees

Example 3, mySQL

SELECT EmployeeId, CONCAT(FirstName, ' ', LastName) AS FullName
FROM Employees

The result will look like:

EmployeeId FullName
1 Mazojys Fxoj
2 Jozzh Lnanyo
3 Syllauu Dfaafk
4 Gecrrcc Srlkrt
5 Jssme Bdnaa
6 Dnnaao Errllov
7 Tyoysww Osk

Leave a Comment