- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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 difference between CONCAT() and CONCAT_WS() functions?
Both CONCAT() and CONCAT_WS() functions are used to concatenate two or more strings but the basic difference between them is that CONCAT_WS() function can do the concatenation along with a separator between strings, whereas in CONCAT() function there is no concept of the separator. Other significance difference between them is that CONCAT()function returns NULL if any of the argument is NULL, whereas CONCAT_WS() function returns NULL if the separator is NULL.
Example
The example below demonstrate the difference between CONCAT() and CONCAT_WS() function −
mysql> Select CONCAT('Ram','is','a','good','student') AS 'Example of CONCAT()'; +---------------------+ | Example of CONCAT() | +---------------------+ | Ramisagoodstudent | +---------------------+ 1 row in set (0.00 sec) mysql> Select CONCAT_WS(' ','Ram','is','a','good','student') AS 'Example of CONCAT_WS()'; +------------------------+ | Example of CONCAT_WS() | +------------------------+ | Ram is a good student | +------------------------+ 1 row in set (0.00 sec)
Advertisements