SQL CONCAT Function: Usage & Examples

In SQL, the CONCAT function is used to combine two or more string values together. Its syntax is as follows:

CONCAT(string1, string2, ...)

In this case, the parameters string1, string2, etc. are the string values to be connected. For example, if we want to concatenate “Hello” and “World” into a single string “Hello World”, we can use the following SQL statement:

SELECT CONCAT('Hello', ' ', 'World');

This will return the result “Hello World”. Additionally, the CONCAT function can also be used to concatenate field values in a table, for example:

SELECT CONCAT(first_name, ' ', last_name) AS full_name
FROM employees;

The query will combine the values of the first_name and last_name fields from the employees table into a new column called full_name.

bannerAds