How to Concatenate Strings in SQLite with ||
To show a full name from separate first and last name columns, you join the two pieces of text into one. In SQLite, the operator for that is ||, two vertical bars. This guide builds full names from two columns, with real output from SQLite 3.54.1.
Syntax
SELECT <text 1> || <text 2> FROM <table>;
| Part | What it means |
|---|---|
<text 1>, <text 2> | The pieces to join: column names, text in single quotes, or numbers |
| The two vertical bars | The concatenation operator. It joins the piece on its left to the piece on its right, and you can chain as many pieces as you need |
SQLite's documentation on operators: "The || operator is "concatenate" - it joins together the two strings of its operands."
Prerequisites
- The sqlite3 command-line shell. This guide uses SQLite 3.54.1. Run
sqlite3 --versionto see yours; the SQLite download page has the command-line tools for Windows, macOS and Linux.
Step 1: Write the Script
Save this as join_text.sql:
CREATE TABLE people (
first_name TEXT NOT NULL,
last_name TEXT NOT NULL
);
INSERT INTO people (first_name, last_name) VALUES ('Ana', 'Silva');
INSERT INTO people (first_name, last_name) VALUES ('Ben', 'Okafor');
SELECT first_name || ' ' || last_name AS full_name FROM people;

first_name || ' ' || last_namejoins three pieces: the first name, a space in single quotes, and the last name.AS full_namenames the result column. Without it, the heading would be the whole expression.
Step 2: Run It
In the folder that holds the script, run:
sqlite3 -table people.db ".read join_text.sql"
sqlite3 opens the database file people.db, and creates it when it isn't there. -table prints each result as a table, and .read runs the statements in the script. The command is the same in bash, zsh and PowerShell.
+------------+
| full_name |
+------------+
| Ana Silva |
| Ben Okafor |
+------------+

Each row came back as one piece of text: the first name and the last name, with a space between them.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
+ between two pieces of text, as in 'Ana' + 'Silva' | It returned 0: + adds numbers, it doesn't join text | Join text with the two vertical bars |
| No space between the pieces | The first name joined straight to the last name gave AnaSilva | Put ' ' between them, as the script does |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| A joined value is empty for some rows | One of its pieces is NULL, and joining anything to NULL gives NULL | Use coalesce() or concat_ws(), as the FAQ shows |
Parse error near line 1 of join_text.sql: table people already exists | The script already ran on people.db | Delete people.db and run the script again |
FAQ
What happens when one piece is NULL?
The whole result is NULL. In a people table with a middle_name column that was NULL for Ana, first_name || ' ' || middle_name || ' ' || last_name IS NULL returned 1. The documentation: "All operators generally evaluate to NULL when any operand is NULL, with specific exceptions as stated below." Wrapping the optional piece in coalesce(), which returns its first argument that isn't NULL, fixes it: first_name || ' ' || coalesce(middle_name || ' ', '') || last_name returned Ana Silva.
Does SQLite have a concat() function?
Yes, concat() and concat_ws(), and both skip NULL pieces. With Ana's NULL middle name, concat(first_name, ' ', middle_name, ' ', last_name) skipped the NULL but kept both spaces around it, so her name came back with two spaces in the middle. concat_ws(' ', first_name, middle_name, last_name) returned Ana Silva. The documentation: "The concat_ws(SEP,...) function returns a string that is the concatenation of all non-null arguments beyond the first argument, using the text value of the first argument as a separator."
Can I join a number to text?
Yes: 'Page ' || 412 returned Page 412, and typeof() reported the result as text.
Conclusion
first_name || ' ' || last_name AS full_name joined each person's two names, with a space between them, into one column.
Additional Resources
- Operators — the concatenation operator and the rest, in precedence order.
- concat() and concat_ws() — joining text while skipping NULL.
- coalesce() — a fallback value for NULL.
