Skip to content

CONCAT, ||

The CONCAT() function concatenates two strings.

The || variant concatenates two or more string arguments.

Syntax

sql
CONCAT(expr1, expr2)

-- or

expr1 || expr2 || ... || exprN

Arguments

expr: Input arguments can be of any data type. If the data type of the argument is not textual, the database implicitly converts the argument to the STRING data type.

Example 1 | 2 Arguments

sql
SELECT concat('Meta', 'Kraftwerk'),
       'Meta' || 'Kraftwerk';
+-----------------------------+-----------------------------+
| CONCAT('META', 'KRAFTWERK') |     'META' || 'KRAFTWERK'   |
|-----------------------------+-----------------------------+
|               MetaKraftwerk |               MetaKraftwerk |
|-----------------------------+-----------------------------+

Example 2 | Multiple Arguments of Different Data Types

sql
SELECT  'Meta' || 'Kraft' ||'werk' as results
UNION ALL 
SELECT  'abc' || 123 ||'def' as results;
+---------------+
|    RESULTS    |
|---------------+
| MetaKraftwerk | 
|     abc123def | 
+---------------+

Example 3 | NULL Values

sql
SELECT 'abcd' || NULL ||'EFGH';
+----------------------+
| 'ABCD'||NULL||'EFGH' |
|----------------------+
|            abcdEFGH  |
+----------------------+