MySQL: Introduction to CONCAT and CONCAT_WS Functions

MySQL supports two types of concatenation functions: CONCAT and CONCAT_WS.

CONCAT function contatenates all the argument values like:

SELECTCONCAT(‘Television’,‘Mobile’,‘Furniture’);

This returns the folowing:

TelevisionMobileFurniture

If you want to concatenate with a comma, specify the comma at the end of each value then pass it as an argument:

SELECT CONCAT('Television,','Mobile,','Furniture');
SELECT CONCAT('Television',',','Mobile',',','Furniture');

This will return the following:

Television,Mobile,Furniture

You can omit the extra work by using CONCAT_WS function. CONCAT_WS means concatenate with separator. This is similar to CONCAT function but accepts the separator as the first argument.

Read the rest of the tutorial here: http://blog.sqlauthority.com/2014/06/07/mysql-introduction-to-concat-and-concat_ws-functions/

Leave a Reply

Your email address will not be published. Required fields are marked *