Knowledge base / SQL
SQL CONCAT: joining text, NULL and engine differences
I explain why one missing field removes the whole result in MySQL while other engines may omit only the missing fragment.

CONCAT combines values into one string. Before using it, I check the engine and the missing-data rule. The same expression containing NULL can produce a label in PostgreSQL and a completely missing result in MySQL. A shared function name does not establish identical behaviour across databases.
The examples below are synthetic. I focus on short strings, separators and missing values, without performance claims or a promise of universal numeric formatting. I checked the scope against official documentation on 22 November 2026.
Basic syntax and an explicit space
In MySQL 8.4, PostgreSQL and SQL Server, the following expression returns Ada Nowak. The space is a separate argument. Without it, the two names would be joined directly. CONCAT cannot infer whether the result represents a person, a product code or an order description.
SELECT CONCAT('Ada', ' ', 'Nowak') AS label;
The same principle applies to columns: CONCAT(first_name, ' ', last_name). Here I assume text fields. Existing leading or trailing spaces are not cleaned merely by inserting another space. I treat normalization and joining as separate decisions, retaining the original values when their quality may need investigation.
NULL depends on the database
MySQL returns NULL if any CONCAT argument is NULL. PostgreSQL ignores NULL arguments, while SQL Server converts them to empty strings. This corrects the rule stated incorrectly in the previous version of this entry.
SELECT CONCAT('A', NULL, 'B') AS label;
| Engine | Result |
|---|---|
| MySQL 8.4 | NULL |
| PostgreSQL | AB |
| SQL Server | AB |
| SQLite from 3.44.0 | AB |
SQLite documents concatenation of the representations of non-NULL arguments. CONCAT and CONCAT_WS were added in SQLite 3.44.0. An application embedding an older SQLite library may lack them even if its client software was installed recently. The relevant version is the engine executing the expression.
COALESCE records a missing-value decision
If an optional fragment may be absent in MySQL, I can explicitly replace it with an empty string. For this synthetic NULL value, the expression returns AB. That choice should follow the label’s requirements rather than a desire to conceal missing source data.
SELECT CONCAT('A', COALESCE(NULL, ''), 'B') AS label;
If a surname is mandatory, I would prefer a separate incomplete-record status. A first-name-only label may look acceptable while hiding a field that needs attention. See the COALESCE entry for replacement values. The function chooses a value mechanically; the report author defines whether that replacement is meaningful.
CONCAT_WS inserts separators between elements
In MySQL and PostgreSQL, the first CONCAT_WS argument supplies the separator and later NULL arguments are skipped. An empty string remains an element. Compare the outcomes before using the function to build descriptions from optional columns.
SELECT CONCAT_WS('|', 'A', NULL, 'B') AS missing_part;
SELECT CONCAT_WS('|', 'A', '', 'B') AS empty_part;
The first result is A|B; the second is A||B. Separators appear between retained elements. If an empty field should count as missing, define its conversion to NULL separately. A string containing spaces is another distinct input and may require its own data-quality decision.
SQL Server supports CONCAT_WS from version 2017. These examples contain a separator and three following arguments, satisfying its requirement for at least two values to join. This is another reason to check the target engine rather than copying the shortest syntax from a different system.

Tie the Oracle rule to its version
Oracle 19c documents CONCAT with two arguments. Nesting joins three fragments. This example for that version uses DUAL and returns Ada Nowak.
SELECT CONCAT(CONCAT('Ada', ' '), 'Nowak') AS label
FROM DUAL;
That restriction should not be extended to every current Oracle version. The 26ai documentation describes two or more arguments. The earlier audit statement that Oracle CONCAT always takes exactly two arguments therefore needs a version qualification. When migrating a query, check the database release as well as the vendor name.
A label does not replace a key or export format
Joining AB and C produces the same string as joining A and BC. Without a separator, field boundaries cannot be reconstructed. A separator alone does not guarantee uniqueness if it can also occur in the data. For joins and record identification, retain the key columns rather than automatically replacing them with a concatenated label.
Likewise, CONCAT_WS with a comma does not by itself produce a valid CSV file. A value can contain commas, quotes or line breaks that need an exporter’s serialization rules. Creating a readable label and serializing structured data are separate tasks. I also avoid promising that the || operator is portable: its meaning depends on the engine and configuration.
For numbers and dates, agree on a target format before joining. Implicit conversion does not promise the decimal places or date layout that a recipient expects. Large text values also have limits depending on the result type; SQL Server documents those on its CONCAT page. A small label example says nothing about unrestricted text length.
Exercise with an optional fragment
Write down the expected result when the middle field contains X, NULL or an empty string. Compare ordinary CONCAT in MySQL with CONCAT_WS using a vertical bar. Then decide whether a missing middle field is allowed in your label. Record that decision in the column description. The key question is whether the final string lets its reader recognize incomplete information.
Key takeaways
Does CONCAT skip NULL in MySQL?
No. In MySQL 8.4, any NULL argument makes CONCAT return NULL. PostgreSQL and SQL Server handle these arguments differently.
Does CONCAT_WS skip empty strings?
In the MySQL and PostgreSQL examples, it skips NULL but retains empty strings, which can create an additional separator.
Does Oracle CONCAT accept only two arguments?
Oracle 19c documents two arguments and nesting. Oracle 26ai documents two or more, so the restriction must be tied to a version.
AI was used in an automated way while working on this article. If you want to learn how to do it too, check out this project.
