MySQL CONCAT_WS() Function

The CONCAT_WS() function combines two or more expressions into one string, with a separator between each expression. WS stands for “With Separator”.

Tutorials dojo strip

MySQL CONCAT_WS Function Syntax

SQL

MySQL CONCAT_WS Function Example

This query returns the combined string ‘SQL-Tutorial-is-fun!’ with – as the separator.

SQL

Note: The CONCAT_WS() function is supported in MySQL but not in SQLite. This example does not work in the TechKubo playground.

MySQL CONCAT_WS Function Parameters

ParameterDescription
separatorRequired. The separator to place between each expression. If NULL, the result is NULL.
expression1, expression2, …Required. The expressions to concatenate. Expressions with NULL values are skipped.

MySQL CONCAT_WS Function Table Column Example

This query returns the full patient info by combining first_name, last_name, and gender, separated by spaces.

SQL

Note: The CONCAT_WS() function is supported in MySQL but not in SQLite. This example does not work in the TechKubo playground. You can use || and manually add separators if needed.

MySQL CONCAT_WS Function Notes

  • Combines multiple expressions with a specified separator.
  • If any expression is NULL, it is skipped (separator is not added for NULL values).
  • If the separator is NULL, the result is NULL.
  • Works in MySQL 4.0 and higher.
  • Not supported in SQLite. In SQLite, use || for string concatenation and insert separators manually.

Tutorials dojo strip