SQLPathLab
String Functions · Basic

CONCAT

joining strings together.

Overview

MySQL CONCAT joins text arguments in order and is useful for display names, codes, or export columns. In MySQL, any NULL argument makes the CONCAT result NULL, so use COALESCE first when the remaining pieces should be kept. Concatenation is convenient for presentation but should not replace sound data modeling or be applied carelessly in indexed filters.

Basic syntax

SELECT CONCAT(first_name, last_name) AS full_name FROM users;

Examples

CONCAT example

Join first_name and last_name from users into full_name and observe how argument order shapes the result.

Sample table

Table:users
users
first_namelast_name
Tom Lee
Jack Chen
Lucy Wang

Run result

result
full_name
TomLee
JackChen
LucyWang

Common issues

What happens when a string function receives NULL?

Check each function; with CONCAT, use COALESCE first when a fallback value is required.

Where does SUBSTRING indexing begin?

Common MySQL syntax starts at 1; verify argument rules when moving to another database.

Does TRIM remove spaces inside a string?

The default removes leading and trailing spaces only, not spaces within the value.

Tags

CommonString

Was this explanation clear?