Tutorial Gateway

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

MySQL Concat_ws string

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. f any of the arguments is Null value, then the 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;
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.

Filed 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

Copyright © 2021ยท All Rights Reserved by Suresh.
About | Contact | Privacy Policy