// strings reference

SQL CONCAT function

Joins strings into one. The trap is NULL: engines disagree on whether one NULL argument makes the whole result NULL, and the || operator can behave differently from CONCAT on the same engine.

カテゴリ
Strings
Returns
string
In this category
1 of 172

構文

CONCAT(a, b, ...)
a || b  -- PostgreSQL, SQLite, Oracle, SQL Server 2025

Each block is a separate form. The support table and the examples show which engine takes which.

エンジンサポート

エンジンSupportメモ
SQL Server はい CONCAT from 2012; the || operator from SQL Server 2025
PostgreSQL はい Supported under this name.
MySQL はい CONCAT returns NULL if any argument is NULL; || means OR unless PIPES_AS_CONCAT is set
SQLite はい CONCAT and CONCAT_WS from SQLite 3.44; || has always existed
Oracle はい CONCAT took exactly two arguments before 23ai; || ignores NULLs

例

Any engine

SELECT CONCAT(first_name, ' ', last_name) AS full_name
FROM users;

PostgreSQL

-- || is stricter: NULL poisons the result
SELECT NULL || 'a' AS strict_concat;  -- NULL

MySQL

SELECT CONCAT_WS(', ', city, region, country) AS place
FROM addresses;

知っておくと便利なこと

  • NULL handling differs by engine: CONCAT on SQL Server, PostgreSQL, SQLite and Oracle treats NULL as an empty string, but MySQL's CONCAT returns NULL if any argument is NULL.
  • The || operator is stricter than CONCAT on PostgreSQL and SQLite: NULL || 'a' is NULL there. Oracle's || ignores NULL operands, so the same expression gives 'a'.
  • On MySQL, || is logical OR by default: 'a' || 'b' returns 0. Use CONCAT, or set sql_mode PIPES_AS_CONCAT.
  • CONCAT never adds separators. CONCAT_WS(', ', a, b, c) does, and skips NULL arguments; it exists on MySQL, PostgreSQL, SQL Server 2017+ and SQLite 3.44+.

Questions about CONCAT

Does CONCAT return NULL if a value is NULL?

Depends on the engine: SQL Server, PostgreSQL, SQLite and Oracle treat NULL as empty; MySQL returns NULL for the whole call. COALESCE each argument if the query has to behave the same everywhere.

What is the difference between CONCAT and ||?

On PostgreSQL and SQLite, NULL || x is NULL while CONCAT skips the NULL. On MySQL, || is logical OR unless PIPES_AS_CONCAT is set. Oracle's || ignores NULLs, and its CONCAT took only two arguments before 23ai. SQL Server only gained || in 2025.

How do I concatenate with a separator?

CONCAT_WS(', ', a, b, c) on MySQL, PostgreSQL, SQL Server 2017+ and SQLite 3.44+; it skips NULL arguments instead of leaving doubled separators. Oracle has no CONCAT_WS, so write a || ', ' || b. For values from many rows, use STRING_AGG.

Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.

// fewer lookups

Functions your engine actually has

SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.