Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Python Programs
    • Java Programs

MySQL Concat_ws string

by suresh

The MySQL Concat_ws string function stands for concatenating with separator. MySQL string concat_ws function is one of the String Function, which is to combine two or more strings along with separator.

TIP: If any of the arguments is Null value, then MySQL concat_ws returns the result as NULL.

MySQL Concat_ws String Syntax

The basic syntax of Concat_ws in MySQL is as shown below:

-- MySQL Concat_WS String Syntax 
SELECT CONCAT_WS (Separator, String 1, String 2,.., String N)
FROM Source

MySQL Concat_ws String Example 1

The MySQL Concat_ws String Function returns the combined string using the separator. The following Concat_ws query shows you the same.

-- MySQL String Concat_ws Example
SELECT CONCAT_WS(',', 'Tutorial', 'Gateway') AS Str1;

SELECT CONCAT_WS(' ', 'Tutorial', 'Gateway') AS Str2;

SELECT CONCAT_WS(' $ ', 'Learn', 'MySQL', 'at', 'Tutorial', 'Gateway') AS Str3;

SELECT CONCAT_WS(' ', 'Learn', 'MySQL', 'at', 'Tutorial', 'Gateway') AS Str4;

As you can see from the below screenshot, it is combining the string using the separator that we specified as the first argument.

MySQL Concat_ws string 1

MySQL Concat_ws String Example 2

In this MySQL example, we are going to concatenate the FirstName and LastName columns present in the Employe using space separator, and dollar separator. To demonstrate this concat_ws string function, We are going to use the employ table data that we have shown below

MySQL Concat_ws string 2

Let me show you the query

-- MySQL String Concat_ws Example
USE `mysql tutorial`;
SELECT  First_Name, 
        Last_Name,
	CONCAT_WS(' ', First_Name, Last_Name) AS FullName1,
        CONCAT_WS(' $ ', First_Name, Last_Name) AS FullName2,
	DepartmentName,
        Email
FROM employe;

OUTPUT

MySQL Concat_ws string 3

TIP: The Concat_ws function is the same as the Concat function. However, this String Function accepts extra argument as the string separator.

Placed Under: MySQL

  • How to Download MySQL
  • Install MySQL on Windows
  • MySQL Create Database
  • MySQL Delete Database
  • MySQL Create Table
  • MySQL Drop Table
  • MySQL SELECT Statement
  • MySQL ALIAS Column
  • MySQL Distinct
  • MySQL Insert Statement
  • MySQL Delete
  • MySQL Truncate Table
  • MySQL WHERE Clause
  • MySQL Order By
  • MySQL Group By
  • MySQL Having Clause
  • MySQL LIMIT
  • MySQL Arithmetic Operators
  • MySQL COALESCE Function
  • MySQL AND Operator
  • MySQL NOT Operator
  • MySQL OR Operator
  • MySQL XOR Operator
  • MySQL BETWEEN Operator
  • MySQL Not Between Operator
  • MySQL GREATEST Function
  • MYSQL LEAST Function
  • MySQL LIKE Operator
  • MySQL NOT LIKE Operator
  • MySQL IFNULL Operator
  • MySQL NULLIF Operator
  • MySQL INTERVAL Operator
  • MySQL IS Operator
  • MySQL IN Operator
  • MySQL NOT IN Operator
  • MySQL IS NOT NULL
  • MySQL IS NULL
  • MySQL Inner Join
  • MySQL Cross Join
  • MySQL Right Join
  • MySQL Left Join
  • MySQL Aggregate Functions
  • MySQL Date Functions
  • MySQL Date Function
  • MySQL String Functions
  • MySQL Numeric Functions
  • C Tutorial
  • C# Tutorial
  • Java Tutorial
  • JavaScript Tutorial
  • Python Tutorial
  • MySQL Tutorial
  • SQL Server Tutorial
  • R Tutorial
  • Power BI Tutorial
  • Tableau Tutorial
  • SSIS Tutorial
  • SSRS Tutorial
  • Informatica Tutorial
  • Talend Tutorial
  • C Programs
  • C++ Programs
  • Java Programs
  • Python Programs
  • MDX Tutorial
  • SSAS Tutorial
  • QlikView Tutorial

Copyright © 2021 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy