// strings reference

SQL || operator

The standard SQL concatenation operator. Cleaner than CONCAT for short joins, but its NULL behaviour and availability differ per engine.

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

構文

a || b || c

エンジンサポート

エンジンSupportメモ
SQL Server Different name or syntax from SQL Server 2025 and Azure SQL Database; use + or CONCAT before that
PostgreSQL はい Supported under this name.
MySQL Different name or syntax only with PIPES_AS_CONCAT in sql_mode; || means logical OR by default
SQLite はい Supported under this name.
Oracle はい Supported under this name.

例

PostgreSQL

SELECT 'cafe' || ' corner' AS place;  -- cafe corner

PostgreSQL

SELECT NULL || 'a' AS strict_concat;  -- NULL

Oracle

SELECT first_name || ' ' || last_name AS full_name FROM users;

知っておくと便利なこと

  • NULL || 'a' is NULL on PostgreSQL, SQLite and SQL Server. Oracle returns 'a': its || treats a NULL operand as an empty string, the flip side of Oracle storing '' as NULL.
  • In MySQL, || is logical OR unless the PIPES_AS_CONCAT flag is in sql_mode, a classic why-is-this-1-instead-of-a-string trap.
  • SQL Server only gained || in SQL Server 2025 (and Azure SQL Database); on 2022 and older the + operator or CONCAT is the only option.
  • Numbers: Oracle and SQLite turn 1 || 2 into '12'. PostgreSQL needs at least one text operand: 'x' || 1 works, 1 || 2 is an operator-does-not-exist error.

Questions about ||

Is || the same on every database?

No. Oracle and PostgreSQL treat it as plain concatenation, MySQL needs PIPES_AS_CONCAT (else it is OR), and SQL Server only supports it from 2025 (and in Azure SQL Database). The NULL rules also differ.

Why does 1 || 1 return 1 in MySQL?

Because MySQL reads || as logical OR: 1 || 1 is 1 (true). Add PIPES_AS_CONCAT to sql_mode, or use CONCAT, to get '11'.

Does || handle NULL like CONCAT?

Usually not: on PostgreSQL and SQLite, NULL || 'a' is NULL while CONCAT('a', NULL) returns 'a'. Oracle's || skips NULLs on both counts.

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

Cheat sheets for the engines that have it: SQL Server, PostgreSQL, MySQL, SQLite, Oracle.

// 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.