How to Concatenate Strings in SQL

  • google plus

In Brief...

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

Instructions

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

Author: Nat Dunn

Nat Dunn founded Webucator in 2003 to combine his passion for web development with his business expertise and to help companies benefit from both.

Discuss