How to Concatenate Strings in SQL

See SQL: Tips and Tricks for similar articles.

SQL Server, Oracle, MySQL and PostgreSQL each have their own way of doing string concatenation.

String Concatenation in SQL Server

In SQL Server, concatenation is done with the + operator.

SELECT FirstName + ' ' + LastName AS FullName
FROM Employees

String Concatenation in Oracle

In Oracle, concatenation is done with the || (two pipes) operator.

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

Oracle also supports the CONCAT() function:

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

String Concatenation in MySQL

In MySQL, concatenation is with the CONCAT() function.

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

String Concatenation in PostgreSQL

In PostgreSQL, like Oracle, concatenation is done with the || (two pipes) operator.

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

PostgreSQL also supports the CONCAT() function:

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