SQL reference

SQL CONCAT: join text together

In Excel, you'd reach for
fx=A2 & " " & B2, =CONCAT(), =TEXTJOIN()

Two ways to glue text together. CONCAT(a, b, …) takes any number of pieces. || is the standard SQL operator, the same idea as Excel's &. CONCAT_WS puts a separator between every piece, like TEXTJOIN.

Syntax

CONCAT(a, ' ', b)
a || ' ' || b
CONCAT_WS(', ', a, b, c)  -- with a separator
Try itEdit the query, then Run
labeldetailscustomer_key
Kavya Haddad (United States)social | 2026-01-01customer-1
Ben Kim (India)partner | 2026-01-01customer-2
Kavya Kim (India)organic_search | 2026-01-02customer-3
Nikhil Tanaka (Nigeria)referral | 2026-01-05customer-4
Elena Nguyen (United Kingdom)social | 2026-01-06customer-5
Leo Garcia (Nigeria)social | 2026-01-07customer-6
Tara Ali (Germany)organic_search | 2026-01-07customer-7
Quinn Lopez (United States)organic_search | 2026-01-08customer-8

8 rows

The NULL trap: with ||, if any piece is empty (NULL) the whole result is empty. CONCAT() treats blanks as empty text instead, which is usually what you want. Use COALESCE(col, '') to be safe with ||.

In other databases

  • MySQL: CONCAT(); || means OR unless configured otherwise
  • SQL Server: CONCAT() or +
  • Postgres, Snowflake, Oracle, SQLite: || and CONCAT()
  • BigQuery: CONCAT() or ||

Your turn

For each ticket build summary like urgent ticket handled by Asha from priority and agent.

This page on one card

SQL CONCAT: join text together: the Excel way (=A2 & " " & B2) and the SQL query, side by side
SQL CONCAT: join text together, on one card: the Excel way and the SQL. Download · Save to Pinterest
The practice data (7 tables)

See every column and sample rows