What || does
In standard SQL, || is the string concatenation operator. It joins two or more strings, or string columns, into one value. For example:
SELECT first_name || ' ' || last_name AS full_name
FROM employees;
Each || adds one more part to the result. The operator comes from the ANSI SQL standard, so the same idea works across several databases, though the details vary.
Which databases support it
| Database | Support for || |
|—|—|
| Oracle, PostgreSQL, SQLite, IBM Db2 | Yes, it joins strings |
| MySQL and MariaDB | Only in PIPES_AS_CONCAT mode; by default it means logical OR |
| SQL Server | SQL Server 2025 and Azure SQL only; earlier versions use + or CONCAT() |
The MySQL trap
In MySQL, || means logical OR unless the PIPES_AS_CONCAT SQL mode is on. Logical OR converts its operands to numbers, and text that doesn’t start with a number becomes 0. So a query that joins text columns with || usually returns 0 rather than the joined text. The same query works as expected in Oracle or PostgreSQL, which is why copying it between engines can go wrong.
In MySQL, you have two options. Use CONCAT(), which joins strings whatever the || setting. Or turn on PIPES_AS_CONCAT for the session if you need || to join text.
NULL handling
In SQL Server, || returns NULL when any input is NULL, the same as + in SQL Server 2017 and later. Other databases handle NULL in concatenation differently, so run a test query before you move code to a different engine.
Which operator to use
- For Oracle, PostgreSQL, SQLite or Db2, use
||. It’s the standard choice for those engines. - For MySQL, use CONCAT(), which doesn’t depend on the
||setting. - For SQL Server, use
+or CONCAT() on all versions. On SQL Server 2025 and Azure SQL,||is also available.
CONCAT() also works in PostgreSQL and SQL Server, so it’s the easiest function to move between MySQL, PostgreSQL and SQL Server.
Joining columns in SQL Server
For SQL Server specifics, including NULLs and spacing, see the guide on merge two columns in sql server. If you want the values from two columns stacked into rows instead of joined, how to combine 2 column into 1 column covers that approach.