What is CONCAT() in SQL?
The CONCAT() function is used to concatenate n number of arguments.
The illustration below shows how the CONCAT() function works.
String 1 (Argument 1)
1 of 6
Syntax
CONCAT(arg1, arg2, .... argn)
Parameter
The CONCAT() function takes in n number of arguments as a parameter.
Return value
The CONCAT() function returns the single string concatenating the arguments sent as parameter.
Example
The example below shows how we can use the CONCAT() function to concatenate the first and last names of the students.
Students
Student ID | Student First Name | Student Last Name |
1 | David | Lew |
2 | Luiss | Kevin |
3 | Harvey | Dave |
4 | Lucy | Dan |
5 | Andrew | Wade |
select *, CONCAT(studentFirstName,' ',studentLastName) as studentFullNamefrom Students
Another example
This example explains some other implementations of the CONCAT() function.
-- concat the numbersSELECT CONCAT(9,10,100);-- concat the number and stringSELECT CONCAT('Educative', 10);