Summary: in this tutorial, you will learn how to concatenate two strings into a string by using the concatenation operator.
The SQL standard provides the CONCAT()
function to concatenate two strings into a single string.
SQLite, however, does not support the CONCAT()
function. Instead, it uses the concatenate operator (||
) to join two strings into one.
Here is the basic syntax of the concatenation operator:
s1 || s2
Code language: SQL (Structured Query Language) (sql)
It is possible to use multiple concatenation operator in the same expression:
s1 || s2 || s3
Code language: SQL (Structured Query Language) (sql)
The following example shows how to concatenate two literal strings into one:
SELECT 'SQLite ' || 'CONCAT';
Code language: SQL (Structured Query Language) (sql)
Here is the output:
'SQLite ' || 'CONCAT'
---------------------
SQLite CONCAT
Code language: SQL (Structured Query Language) (sql)
And this example illustrates how to use two concatenation operators:
SELECT 'SQLite' || ' ' || 'CONCAT';
Code language: SQL (Structured Query Language) (sql)
The output is:
'SQLite' || ' ' || 'CONCAT'
---------------------------
SQLite CONCAT
Code language: SQL (Structured Query Language) (sql)
See the following table Employees
from the sample database:
This example shows how to construct full name of employees from the first name, space, and last name:
SELECT
FirstName || ' ' || LastName AS FullName
FROM
Employees
ORDER BY
FullName;
Code language: SQL (Structured Query Language) (sql)
Here is the output:
In this tutorial, you have learned how to use the SQLite concatenation operator (||) to concatenate two strings into a single string.