CONCAT
CONCAT is a SQL function that is used to join two or more strings into one single string.
CONCAT(str1, str2, …, strn)
- str1: This is the first string value. It is this parameter where the concatenation procedure starts.
- str2: This is the second string value. This parameter is appended to the end of the first string (str1).
- …, strn: These represent any number of additional string values, which are appended in order to the end of the previously concatenated string. The CONCAT function accepts any number of parameters greater than zero.
Example
Output
Explanation
The CONCAT function in MySQL concatenates two or more strings into one. In the provided example, ‘Hello’ and ‘World’ are concatenated with a space between them to form ‘Hello World’. The result of this concatenation is titled ‘Greeting’.
CONCAT(argument1, argument2, …)
- argument1: The first string of characters to be concatenated.
- argument2: The second string of characters to be concatenated.
- …: Represents additional string parameters that can be included. These strings will be concatenated in the order in which they are provided. This is optional.
Example
Output
Explanation
The CONCAT
function combines two or more strings into one. The example code merges ‘Hello, ’ and ‘World!’ into a single string ‘Hello, World!’.
CONCAT( string_value1, string_value2 [, string_valueN ] )
- string_value1: The first string value to combine. This value must be a string and it is mandatory.
- string_value2: The second string value to combine with the first one. This value is also mandatory and must be a string.
- string_valuen: One or more additional string values to add to the combination. These values are optional and can vary in number. They must also be strings.
Example
Output
ConcatenatedString |
---|
SQL Server |
Explanation
In the provided SQL snippet, ‘SQL’ and ’ Server’ are concatenated using the CONCAT
function. The CONCAT
function ignores NULL values and returns a string that is the combination of input values. The output for the above SQL code will be ‘SQL Server’.
CONCAT(string1, string2)
- string1: The first string value that you want to concatenate.
- string2: The second string value that you want to concatenate.
Example
Output
Explanation
In the above example, the CONCAT
function is used to join two strings, ‘Hello’ and ’ World’. The output is a new combined string ‘Hello World’.
CONCAT(string1, string2, …, string_n)
- string1: The first string value that needs to be concatenated. It can be a string literal, variable, or column.
- string2: The second string value to be concatenated with the first string.
- …: This implies that the CONCAT() function can take in more than two string values.
- string_n: The nth string value to be concatenated. The function can handle any number of string inputs.
Example
Output
Explanation
The CONCAT
function combines the strings ‘Hello’, ’ ’, and ‘World’ into a single output string ‘Hello World’.