CONCAT() in MySQL — How It Works

What the MySQL CONCAT() function does, with an example.

Published October 18, 2026

CONCAT() joins two or more strings into one. If any argument is NULL, the result is NULL.

How it works

Use CONCAT_WS(separator, ...) to join with a separator and skip NULLs. Numbers are converted to strings automatically.

Try it in MySQL

SELECT CONCAT('Hello', ' ', 'World')
Hello World
SELECT CONCAT('a', NULL, 'b')
NULL
SELECT CONCAT_WS('-', '2026', '11', '12')
2026-11-12

Practical examples

Example 1

SELECT CONCAT('Hello', ' ', 'World');
-- Hello World

Example 2

SELECT CONCAT('a', NULL, 'b');
-- NULL

Example 3

SELECT CONCAT_WS('-', '2026', '11', '12');
-- 2026-11-12

Use it in a real query

SELECT id, CONCAT('Hello', ' ', 'World') AS result
FROM your_table
LIMIT 10;

Common mistakes

  • Forgetting any NULL argument makes the result NULL (use IFNULL or CONCAT_WS).
  • Using || which is OR in MySQL by default.
  • Building SQL with CONCAT from user input (injection risk).

Key takeaways

  • CONCAT() in one line: CONCAT() joins two or more strings into one.
  • Try queries in a test database first.
  • Check NULL handling and data types.

FAQ

CONCAT vs CONCAT_WS?

CONCAT_WS adds a separator and ignores NULL values.

Does CONCAT() work in other databases?

Most have an equivalent, but names and syntax vary between MySQL, PostgreSQL, SQL Server and SQLite.

More SQL articles