Concat Columns with Separators in MySQL

0

There are times when you prefer using mysql function over PHP function. For example in case of fetching name of user from a table you want to get the concatenated user name  (first name, middle name, last name). In these cases you can use CONCAT_WS() functions provided in mysql.

As stated in the official documentation, CONCAT_WS() stands for Concatenate With Separator and is a special form of CONCAT(). CONCAT_WS() does not skip empty strings. However, it does skip any NULL values after the separator argument.

Take a look at a sample example below. First create a table with some sample data.

Concatenate the user name with a blank space separator using CONCAT_WS() function.

 

 

Share.
 

About Author

Entrepreneur & Dreamer

I am a passionate Software Professional, love to learn and share my knowledge with others.

Software is the hardware of my life.

Leave A Reply

CommentLuv badge

Get more stuff like this
in your inbox

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.