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 Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>