SQL Query

How to Concatenate Strings in SQL

Combine multiple strings or columns into one using CONCAT or || operator.

How to Concatenate Strings in SQL

Combine multiple strings or columns into one using CONCAT or || operator.

Quick Answer

SELECT CONCAT(first_name, ' ', last_name) as full_name FROM users;

Explanation

CONCAT joins strings together. || operator works in PostgreSQL/Oracle. CONCAT_WS adds a separator between values. Use COALESCE to handle NULLs.

Query Variants

Concat

SELECT CONCAT(first_name, ' ', last_name) as full_name FROM users;

Pipe

SELECT first_name || ' ' || last_name as full_name FROM users;

Concat Ws

SELECT CONCAT_WS(', ', city, state, country) as location FROM addresses;

With Null

SELECT CONCAT(COALESCE(prefix, ''), name) as full_name FROM users;

Pro Tips

  • CONCAT_WS handles separators automatically
  • NULL in CONCAT may return NULL (database-dependent)
  • Use COALESCE for NULL-safe concatenation

Related SQL Queries

Continue learning with more SQL query examples:

Related Content

From Our Blog

Try it yourself

Practice this query in our interactive SQL sandbox.