SELECT CONCAT_WS(":", "String 1", "String 2", "String 3", "String4") AS my_str;
Output is here
String 1:String 2:String 3:String4
We used ':' as separator here and all strings are joined using this separator. We will use this in our student table. ( download sql_dump from our concat tutorial. )
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 |
SELECT CONCAT_WS(COALESCE(f_name,'-',' '),' ',COALESCE(l_name,'-')) as name,class FROM `student_name`
| name | class |
|---|---|
| JohnDeo | Four |
| Larry- | Four |
| Ronald- | Five |
| GarryMiller | Five |
| -- | Five |
| -Ruller |
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.