This tutorial explains how to use the MySQL CONCAT_WS function with syntax and examples.
The MySQL CONCAT_WS function allows you to concatenate two or more expressions together and adds a separator between each of the concatenated expressions.
The syntax for the CONCAT_WS function in MySQL is:
CONCAT_WS( separator, expression1, expression2, ... expression_n )
The separator that is added between each of the concatenated expressions.
The expressions to concatenate together.
The CONCAT_WS function can be used in the following versions of MySQL:
Let's look at some MySQL CONCAT_WS function examples and explore how to use the CONCAT_WS function in MySQL.
For example:
mysql> SELECT CONCAT_WS(',', 1, 2, 3, 4);
Output: '1,2,3,4'
mysql> SELECT CONCAT_WS(', ', 1, 2, 3, 4);
Output: '1, 2, 3, 4'
mysql> SELECT CONCAT_WS('ABC', 'x', 'y', 'z');
Output: 'xABCyABCz'
mysql> SELECT CONCAT_WS('ABC', 'x', 'y', NULL, 'z');
Output: 'xABCyABCz'
mysql> SELECT CONCAT_WS(NULL, 'x', 'y', 'z');
Output: NULL