Watch the 7.3 Webinar On-Demand
This new release brings updates to Universal Storage, query
optimization, and usability that you won’t want to miss.
Concatenates all of the values in its argument list. If any of the arguments is NULL
, the result is NULL
. When PIPES_AS_CONCAT
flag is on, the symbol || can be used as CONCAT as well.
This function is not to be confused with GROUP_CONCAT, which is an aggregate function returning a concatenation of values passed in during aggregation.
CONCAT(expression, [ expression, [expression ...]])
expression || expression || expression ... || expression
The concatenated string.
||
can take two different roles. If the sql_mode
session variable is set as PIPES_AS_CONCAT
, then
||
is an alias for the CONCAT function else, it is an alias for logical OR
.sql_mode
variable is checked each time ||
symbol is encountered. The role of the symbol changes accordingly.||
symbol has a higher precedence than the logical OR
.SELECT CONCAT('1', '2', '3');
+-----------------------+
| CONCAT('1', '2', '3') |
+-----------------------+
| 123 |
+-----------------------+
SELECT CONCAT('1', ' ', '2', ' ', '3');
+---------------------------------+
| CONCAT('1', ' ', '2', ' ', '3') |
+---------------------------------+
| 1 2 3 |
+---------------------------------+
SELECT CONCAT(first_name, " ", last_name) FROM BFFs;
+------------------------------------+
| CONCAT(first_name, " ", last_name) |
+------------------------------------+
| Cecelia Cruz |
| Ari Floo |
| Skylar Rhodes |
+------------------------------------+
SET @@sql_mode = PIPES_AS_CONCAT;
SELECT 'a' || 'b' || 'c';
+-------------------+
| 'a' || 'b' || 'c' |
+-------------------+
| abc |
+-------------------+
SELECT first_name || " " || last_name FROM BFFs;
+--------------------------------+
| first_name || " " || last_name |
+--------------------------------+
| Cecelia Cruz |
| Ari Floo |
| Skylar Rhodes |
+--------------------------------+
SELECT '1 ' || CONCAT('2 ', '3');
+---------------------------+
| '1 ' || CONCAT('2 ', '3') |
+---------------------------+
| 1 2 3 |
+---------------------------+