This guide is specifically for MySQL syntax.
SQL Query to Concatenate Strings
Combine multiple strings or columns into one using CONCAT or || operator.
Quick Answer
SELECT CONCAT(first_name, ' ', last_name) as full_name FROM users;
Explanation
CONCAT joins strings together. || operator works in PostgreSQL/Oracle. CONCAT_WS adds a separator between values. Use COALESCE to handle NULLs.
Query Variants
Concat
SELECT CONCAT(first_name, ' ', last_name) as full_name FROM users;
Pipe
SELECT first_name || ' ' || last_name as full_name FROM users;
Concat Ws
SELECT CONCAT_WS(', ', city, state, country) as location FROM addresses;
With Null
SELECT CONCAT(COALESCE(prefix, ''), name) as full_name FROM users;
Pro Tips
- CONCAT_WS handles separators automatically
- NULL in CONCAT may return NULL (database-dependent)
- Use COALESCE for NULL-safe concatenation
Related SQL Queries
Continue learning with more SQL query examples:
MySQL-Specific Notes
This page covers MySQL syntax. Other databases may have different syntax for similar operations.