// dialect comparison

String concatenation in SELECT: || vs + vs CONCAT

Same task, three operators, and the NULL rules differ between them.

Filed under Querying

The verdict

|| is the standard and the most widely supported, but MySQL needs CONCAT() and SQL Server before 2025 needs +. NULL handling splits further: Oracle ignores NULLs in ||, SQL Server's CONCAT ignores them, MySQL's CONCAT does not, and every other operator returns NULL. Wrap nullable operands in COALESCE(…, '') or use CONCAT_WS when a missing last name must not blank the whole value.

Where they differ

PostgreSQL, SQLite and Oracle use the standard || operator. SQL Server uses + (|| arrived only in SQL Server 2025 and Azure SQL), and MySQL uses CONCAT(). The porting bug is NULL handling: || and + return NULL when any operand is NULL, except in Oracle.

How each engine writes it

SQL Server

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

+ returns NULL if any operand is NULL; CONCAT() treats NULL as an empty string. SQL Server 2025 and Azure SQL also accept ||.

PostgreSQL

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

|| returns NULL on a NULL operand; CONCAT() and CONCAT_WS() skip NULLs.

MySQL

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

|| means logical OR unless sql_mode includes PIPES_AS_CONCAT. CONCAT returns NULL if any argument is NULL; CONCAT_WS skips NULLs.

SQLite

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

|| returns NULL on a NULL operand. concat() and concat_ws(), which skip NULLs, arrived in 3.44.

Oracle

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

Oracle treats NULL as an empty string here, so 'Ana' || ' ' || NULL is 'Ana '. CONCAT() took exactly two arguments before 23ai.

Questions that come up

Why is my concatenated column NULL?

One operand is NULL and the operator propagates it: + in SQL Server, || in PostgreSQL and SQLite, CONCAT() in MySQL. Use COALESCE(last_name, ''), or CONCAT_WS(' ', first_name, last_name), which skips NULLs in SQL Server 2017+, PostgreSQL, MySQL and SQLite 3.44+.

Can I concatenate numbers?

|| converts numbers to text in PostgreSQL, SQLite and Oracle, and CONCAT() does in every engine. SQL Server's + does not: 'Order ' + 42 tries to convert the string to int and fails, so use CONCAT or CAST. The text form also varies: 1.0 || '' gives '1.0' in PostgreSQL and SQLite but '1' in Oracle.

How do I concatenate many rows into one string?

That is string aggregation: STRING_AGG(name, ', ') in SQL Server 2017+ and PostgreSQL, GROUP_CONCAT(name SEPARATOR ', ') in MySQL, group_concat() or string_agg() (3.44+) in SQLite, LISTAGG(name, ', ') WITHIN GROUP (ORDER BY name) in Oracle.

Keep reading

// write it once, run it anywhere

Switch engines without relearning SQL

SQLly is a native SQL workbench for macOS, Windows and Linux. Its formatter and plan viewer work in all five dialects.