Use a combination of CONCAT and IFNULL (to handle the NULL case):
Tag Archives: concat
Concatenate and NULL/Blank fields
CONCAT() and RTRIM() both return NULL if any of their arguments are NULL. So CONCAT(‘xyz’, NULL) returns NULL. RTRIM(NULL) returns NULL. CONCAT(‘xyz’, NULL, ‘123’) returns NULL. coalesce(FIELD, ‘—‘)
Mysql Concat + Join fields
SELECT CONCAT(last_name,’, ‘,first_name) full_name FROM mytable ORDER BY full_name; [ad code=1]