In MySQL, how can I combine two or more strings along with a separator?

MySQLMySQLi Database

In MySQL, we can combine two or more strings along with a separator by using CONCAT_WS() function. The syntax of this function is CONCAT_WS(Separator, String1,String2,…,StringN)

Here, the arguments of CONCAT_WS functions are Separator and the strings which need to be concatenated along with that separator as a single string. Separator except for numeric value must enclose within quotes.


mysql> Select CONCAT_WS('.','www','tutorialspoint','com');
| CONCAT_WS('.','www','tutorialspoint','com') |
|                      |
1 row in set (0.00 sec)

In this example above, we can see that the separator ‘.‘ (i.e. a dot) inserted between three strings, www, tutorialspoint and com) which needs to be concatenated.

Updated on 20-Jun-2020 13:50:36