CONCAT_WS
Joins strings, inserting the given separator between them.
MySQL 8.1
CONCAT_WS(separator, str[, ...])Parameters
- separatorVARCHAR
- Separator inserted between the strings
- strVARCHAR
- String to join
Return value
A string; NULL arguments are skipped, but a NULL separator gives NULL
Examples
Date from parts
MySQL 8.1
SELECT CONCAT_WS('-', '2024', '03', '08');Full name from three columns
MySQL 8.1
SELECT CONCAT_WS(' ', last_name, first_name, middle_name) AS full_name
FROM Teacher;Details
Unlike CONCAT, CONCAT_WS skips NULL arguments instead of returning NULL.
Empty strings are not skipped, and the separator is placed around them too: CONCAT_WS('-', 'a', '', 'b') returns a--b.