- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the use of MySQL CONCAT_WS() function?
Basically, MySQL CONCAT_WS() function is used to concatenate two or more strings along with a separator. Here the keyword WS in CONCAT_WS() means WITH SEPARATOR. We can pronounce CONCAT_WS() function as concatenation function with a separator.
Syntax
CONCAT_WS(Separator, String1,String2,…,StringN)
Here, the arguments of CONCAT_WS functions are Separator and the strings which need to be concatenated along with that separator as a single string. Separator except for numeric value must enclose within quotes.
Example
mysql> SELECT CONCAT_WS(' ','New', 'Delhi'); +-------------------------------+ | CONCAT_WS(' ','New', 'Delhi') | +-------------------------------+ | New Delhi | +-------------------------------+ 1 row in set (0.00 sec)
In this example above, we can see that the string ‘ ‘ (i.e. a white space) works as a separator and inserted between two strings, New and Delhi) which needs to be concatenated.
mysql> SELECT CONCAT_WS(' is our ','Delhi','Capital'); +-----------------------------------------+ | CONCAT_WS(' is our ','Delhi','Capital') | +-----------------------------------------+ | Delhi is our Capital | +-----------------------------------------+ 1 row in set (0.00 sec)
In this example above, we can see that the string ‘ is our ‘ works as a separator and inserted between two strings, Delhi and Capital, which needs to be concatenated.
- Related Articles
- What is the use of MySQL SUBSTRING_INDEX() function?
- What is the use of MySQL UNHEX() function?
- What is the use of MySQL CHAR() function?
- What is the use of MySQL FROM_UNIXTIME() function?
- What is the use of MySQL GET_FORMAT() function?
- What is the use of MySQL LAST_INSERT_ID() function?
- What is the use of MySQL TRUNCATE() function?
- What MySQL returns if we use NULL, as both the arguments, as one of the argument and as a separator, in CONCAT_WS() function?
- What is the use of FIND_IN_SET () function in MySQL?
- What is the use of LOCATE() function in MySQL?
- How can CONCAT_WS() function be used with MySQL WHERE clause?
- What is the use of MySQL IFNULL() control flow function?
- What is the use of MySQL NULLIF() control flow function?
- MySQL concat_ws() method usage
- What is the difference between CONCAT() and CONCAT_WS() functions?
