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
Related Articles
- Reset Root Password in MySQL on Windows
- How to Create an ER Diagram for a MySQL Database with Free Tools
- How to Round Up in SQL
- How to Concatenate Strings in SQL (this article)
- How to Select All Columns in a Row in SQL
- How to Check Multiple Conditions in SQL
- How Work with White Space and Semicolons in Simple SQL Selects
- How to Sort Records in SQL
- How to Write Subqueries (Simple and Correlated)