THE WORLD'S LARGEST WEB DEVELOPER SITE

MySQL CONCAT_WS() Function

❮ MySQL Functions

Example

Concatenate several expressions together, and add a separator between them:

SELECT CONCAT_WS("-", "SQL", "Tutorial", "is", "fun!") AS ConcatenatedString;
Try it Yourself »

Definition and Usage

The CONCAT_WS() function concatenates two or more expressions together and adds a separator between them.

Note: See also the CONCAT() function.

Syntax

CONCAT_WS(separator, expression1, expression2, expression3,...)

Parameter Values

Parameter Description
separator Required. The separator to add between each of the concatenated expressions. If separator is a NULL, this function will return a NULL value
expression1,
expression2,
expression3,
etc.
Required. The expressions to concatenate together. Expressions that contain a NULL value will be skipped

Technical Details

Works in: MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23

More Examples

Example

Concatenate three columns (and add a space between them) into one "Address" column:

SELECT CONCAT_WS(" ", Address, PostalCode, City) AS Address
FROM Customers;
Try it Yourself »

❮ MySQL Functions