CONCAT_WS function in MySQL

CONCAT_WS() FUNCTION
The MySQL CONCAT_WS function is used to concatenate two or more expressions together. It also allows to add a separator between each of the concatenated expressions. The various versions of MySQL support the CONCAT_WS function, namely, MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0 and MySQL 3.23.

Syntax:

CONCAT_WS( separator, expr_1, expr_2, ... expr_n )

Parameters:

separator: It is used to specify the separator to add.
expr_1, expr_2, … expr_n: It is used to specify the expressions to concatenate.

Example 1:

mysql> SELECT CONCAT_WS (‘,’, 1, 7, 9, 67);

Output:

‘1, 7, 9, 67’

Explanation:

The expressions are concatenated with the separator ‘,’.

Example 2:

mysql> SELECT CONCAT_WS (‘_’, ‘apple’, ‘boy’, ‘cat’, ‘dog’);

Output:

‘apple_boy_cat_dog’

Explanation:

The expressions are concatenated with the separator ‘_’.