CONCAT Function - SQL


Overview


The CONCAT function in SQL concatenates two or more strings into one string. It is useful for combining multiple strings into a single string.

Example:

SELECT CHAR_LENGTH(string1, string2, ..., stringN)

Syntax:

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

string1, string2, ..., stringN are the strings you want to concatenate into a single string.

Sample Data:

department_id first_name
3 Frank
2 Jane
3 Ashley
NULL Glenn
2 Kelly
1 Richard
1 George
5 Kyle
2 James
1 Gustavo

Example: Hard-coded value


In this example, we are combining the following strings together: ‘Hello,’ ‘-,’ and ‘World,’ for the following output: ‘Hello-World.’


Example: Query without the WHERE Statement


In this example, we are combining the department_id column with the first_name column.


Example: Query with the WHERE Statement


In this example, we are combining the department_id column with the first_name column where the department_id column equals 1.