CONCAT_WS
Joins strings, inserting the given separator between them.
MySQL 8.4
CONCAT_WS(separator, str[, ...])- [ ]optional part
- ...can be repeated
- separator
- Separator inserted between the stringsVARCHAR
- str
- String to joinVARCHAR
Return value
A string; NULL arguments are skipped, but a NULL separator gives NULL
Examples
Date from parts
MySQL 8.4
SELECT CONCAT_WS('-', '2024', '03', '08');Full name from three columns
MySQL 8.4
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.