SQL CONCAT Function

Quick summary: The SQL CONCAT() function joins multiple strings into one.

SQL CONCAT Syntax

CONCAT(string1, string2, ...)
SQL

SQL CONCAT Basic examples

SELECT CONCAT(first_name, ' ', last_name) FROM users;
SQL
Output:
Full names

Concatenates string values.

SQL CONCAT Real-world usage

SELECT CONCAT('Order #', id) FROM orders;
SQL
Output:
Order labels

Builds human-readable strings.

SQL CONCAT Edge cases

SELECT CONCAT(NULL, 'abc');
SQL
Output:
NULL

If any argument is NULL, result is NULL (MySQL behavior).

SQL CONCAT Common mistakes

Concatenating NULL values

NULL propagates through CONCAT.

Incorrect
CONCAT(first_name, last_name)
Correct
CONCAT(COALESCE(first_name,''), COALESCE(last_name,''))

Use COALESCE to avoid NULL results.

SQL CONCAT Frequently Asked Questions

What does CONCAT() do in SQL?

Combines multiple strings into one.

Use case of CONCAT()?

Building full names or messages.

Syntax?

CONCAT(str1, str2, ...).

Handles NULL?

Returns NULL if any argument is NULL (depends on DB).

Common mistake?

Not handling NULL values.

Alternative?

|| operator (DB-specific).

Return type?

String.

Performance?

Fast.

Supports numbers?

Yes, auto-cast.

Used in SELECT?

Yes.

Used in formatting?

Yes.

Best practice?

Handle NULL with COALESCE.

SQL CONCAT Related SQL Keywords