MySQL MySQL CONCAT() AND CONCAT_WS() functions

MySQL CONCAT() AND CONCAT_WS() functions

MySQL concat and concat-ws functions - techbriefers.com

MySQL CONCAT() function

MySQL CONCAT() function is basically a string function , that means it is used to do operations on strings. This function is used to concatenate one or more strings passed as arguments separated by comma, followed by each string. It returns a string which is the result of concatenating the arguments in the same sequence the arguments are passed.
If any of the arguments passed in MySQL CONCAT() function is NULL then it returns NULL. Any numeric argument is automatically converted to its equivalent non binary string form (1 = ‘1’). If any argument id a binary string then the result will be a binary string otherwise a non binary string will be returned as result.

Let’s see with examples

MySQL concat function techbriefers.com
MySQL concat function techbriefers.com
MySQL concat function with null argument techbriefers.com
MySQL concat function with null argument techbriefers.com
MySQL concat function with numeric argument techbriefers.com
MySQL concat function with numeric argument techbriefers.com
MySQL concat function with a binary string argument techbriefers.com
MySQL concat function with a binary string argument techbriefers.com

MySQL CONCAT_WS() function

MySQL CONCAT_WS() function is also used to do concatenation operations on strings, but with a separator. This function is used to concatenate one or more strings passed as arguments with a custom separator. The first argument passed is the separator for all the following strings passed (separated by comma).

The separator is added between the strings concatenated. If the separator passed in MySQL CONCAT_WS() function is NULL then it returns NULL otherwise NULL strings are ignored but blank values are not ignored.

Let’s see with examples

MySQL concat_ws function - techbriefers.com
MySQL concat_ws function – techbriefers.com
MySQL concat_ws function with null separator - techbriefers.com
MySQL concat_ws function with null separator – techbriefers.com
MySQL concat_ws function with blank separator - techbriefers.com
MySQL concat_ws function with blank separator – techbriefers.com
MySQL concat_ws function with blank string - techbriefers.com
MySQL concat_ws function with blank string – techbriefers.com
MySQL concat_ws function with null string - techbriefers.com
MySQL concat_ws function with null string – techbriefers.com

These functions can be easily used to concatenate column values. Below is given example to try with table data.
Click here to Learn SQL.

Example of MySQL CONCAT() function:

Example of MySQL CONCAT_WS() function:

MySQL concat_ws function example - techbriefers.com
MySQL concat_ws function example – techbriefers.com

Share your thoughts

avatar
  Subscribe  
Notify of