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 ||.
Same task, three operators, and the NULL rules differ between them.
Filed under Querying
|| 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.
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.
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 ||.
SELECT first_name || ' ' || last_name AS full_name FROM users;
|| returns NULL on a NULL operand; CONCAT() and CONCAT_WS() skip NULLs.
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.
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.
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.
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+.
|| 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.
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.
COALESCE everywhere; ISNULL, IFNULL and NVL are the same idea with local names.
Doubling the quote works everywhere; three engines offer nicer ways out.
CASE is everywhere; IIF, IF and DECODE are the local shortcuts.
SQLly is a native SQL workbench for macOS, Windows and Linux. Its formatter and plan viewer work in all five dialects.