SQL CONCAT: join text together
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
| label | details | customer_key |
|---|---|---|
| Kavya Haddad (United States) | social | 2026-01-01 | customer-1 |
| Ben Kim (India) | partner | 2026-01-01 | customer-2 |
| Kavya Kim (India) | organic_search | 2026-01-02 | customer-3 |
| Nikhil Tanaka (Nigeria) | referral | 2026-01-05 | customer-4 |
| Elena Nguyen (United Kingdom) | social | 2026-01-06 | customer-5 |
| Leo Garcia (Nigeria) | social | 2026-01-07 | customer-6 |
| Tara Ali (Germany) | organic_search | 2026-01-07 | customer-7 |
| Quinn Lopez (United States) | organic_search | 2026-01-08 | customer-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:
||andCONCAT() - BigQuery:
CONCAT()or||
Your turn
For each ticket build summary like urgent ticket handled by Asha from priority and agent.
CONCAT(priority, ' ticket handled by ', agent).
This page on one card
