How to Concatenate Strings in MySQL

Last updated August 26, 2026 · By the SaturnSQL team

Use CONCAT to join strings and CONCAT_WS to join with a separator while skipping NULLs. The || operator is logical OR in MySQL by default, not concatenation, unless sql_mode includes PIPES_AS_CONCAT.

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

CONCAT_WS skips NULLs

SELECT CONCAT_WS(', ', street, city, postal_code) AS address
FROM customers;

CONCAT returns NULL if any argument is NULL. Wrap optional parts in COALESCE(col, '') or switch to CONCAT_WS, which ignores NULL arguments entirely.

CONCAT returns NULL if any argument is NULL

This is the behaviour that silently empties a column: one missing middle name and the whole assembled string becomes NULL rather than a shorter string. CONCAT_WS is the fix, because it skips NULL arguments instead of propagating them, and it puts the separator only between the values that survived.

SELECT CONCAT('a', NULL)            AS gives_null,
       CONCAT_WS(', ', 'a', NULL)   AS gives_a;

|| does not concatenate in MySQL

Coming from Postgres or Oracle, the obvious guess is ||, and MySQL answers 0 rather than raising an error, because by default || is the logical OR operator and the two strings evaluate as falsy numbers. Use CONCAT, or switch the session to ANSI mode if you are porting a lot of SQL and want || to behave the way the standard says.

SELECT 'a' || 'b';  -- 0

SET sql_mode = 'PIPES_AS_CONCAT';
SELECT 'a' || 'b';  -- ab

Run this in SaturnSQL

SaturnSQL is a browser-based SQL editor for teams: shared query library, schema-aware autocomplete, and scheduled exports to Google Sheets and Slack.

Try it free

Do more with MySQL

Related MySQL guides