In this guide, we will explain how to use the MySQL CONCAT function with syntax and examples.
Description
The MySQL CONCAT function allows you to concatenate two or more expressions together.
Syntax
The syntax for the CONCAT function is:
CONCAT( expression1, expression2, ... expression_n )
Parameters or Arguments
expression1, expression2, … expression_nThe expressions to concatenate together.
Note
- If expression is a numeric value, it will be converted by the CONCAT function to a binary string.
- If all expressions are nonbinary strings, the CONCAT function will return a nonbinary string.
- If any of the expressions is a binary string, the CONCAT function will return a binary string.
- If any of the expressions is a NULL, the CONCAT function will return a NULL value.
- See also the CONCAT_WS function.
Applies To
The CONCAT function can be used in the following versions :
- MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23
Example
Let’s look at some MySQL CONCAT function examples and explore how to use the CONCAT function.
For example:
mysql> SELECT CONCAT('ad', 'gl', 'o', 'b', '.in'); Result: 'adglob.in' mysql> SELECT CONCAT('The answer is ', 24); Result: 'The answer is 24' mysql> SELECT CONCAT('The answer is ', 10+10); Result: 'The answer is 20' mysql> SELECT CONCAT('adglob.in', NULL); Result: NULL
You can also concatenate expressions together in MySQL by placing the strings next to each other.
For example:
mysql> SELECT 'ad' 'gl' 'o' 'b' '.in'; Result: 'adglob.in' mysql> SELECT 'The answer is ' '24'; Result: 'The answer is 24' mysql> SELECT 'The answer is ' '10+10'; Result: 'The answer is 10+10'
Using the above method of concatenation, each of the expressions must be a string.
Next Topic : Click Here
Pingback: MySQL: CHARACTER LENGTH Function | Adglob Infosystem Pvt Ltd