SELECT concat_ws(':',f_name,' ',l_name) as name,class FROM `student_name`
name
class
John: :Deo
Four
Larry:
Four
Ronald:
Five
Garry: :Miller
Five
Five
:Ruller
You can see in above records if any one of the string ( or column ) is null then the value returned by CONCAT_WS is null. We can change this and return any specific string by using COALESCE.
SELECT CONCAT_WS(COALESCE(f_name,'-',' '),' ',COALESCE(l_name,'-')) as name,class FROM `student_name`