The CONCAT() function combines two or more expressions (strings) into one string.
MySQL CONCAT Function Syntax
SQL
x
1
CONCAT(expression1, expression2, expression3, ...);
MySQL CONCAT Function Example
This query returns the combined string 'SQL Tutorial is fun!'
.
SQL
1
1
SELECT CONCAT('SQL ', 'Tutorial ', 'is ', 'fun!') AS ConcatenatedString;
Note: The CONCAT() function is supported in MySQL but not in SQLite. This example does not work in the TechKubo playground. You can use || (string concatenation operator) in SQLite instead.
MySQL CONCAT Function Parameters
Parameter | Description |
---|---|
expression1, expression2, … | Required. The expressions to add together. If any expression is NULL, the result will be NULL. |
MySQL CONCAT Function Table Column Example
This query returns the full name of each patient by combining the first_name and last_name columns.
SQL
1
1
SELECT CONCAT(first_name, ' ', last_name) AS FullName
2
FROM Patients;
Note: The CONCAT() function is supported in MySQL but not in SQLite. This example does not work in the TechKubo playground. You can use first_name || ‘ ‘ || last_name in SQLite instead.
MySQL CONCAT Function Notes
- Combines multiple expressions into one string.
- If any expression is
NULL
, the result will beNULL
.- Works in MySQL 4.0 and higher.
- Not supported in SQLite. In SQLite, use
||
(double pipe) for string concatenation.