CONCAT
- SQL course
- Beginner
- Lesson 40/115
- 4 min
Join strings with CONCAT.
CONCAT
With CONCAT you join texts. The || operator does the same.
SELECT CONCAT(name, ' ', city) AS etiket FROM customers;This query joins name and city with a space between.
CONCAT(name, ' ', city) AS etiket is selected from customers.
CONCAT — details
CONCAT treats NULL as empty text; || returns NULL if any operand is NULL. This difference matters.
Practice CONCAT
Join name and city with a space as label from customers.
Starter code
-- join texts
SELECT
FROM customersSample solution
SELECT CONCAT(name, ' ', city) AS etiket
FROM customersExpected output
etiket Ayşe İstanbul Alex Berlin
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Concatenate
SELECT ____(name, ' ', city) FROM customers;
SELECT CONCAT(name, ' ', city) FROM customers;
Explanation: CONCAT joins the given texts in order; ' ' between them adds a space.
2 CONCAT: match the terms
| Term | Meaning |
|---|---|
CONCAT |
join |
|| |
operator |
UPPER |
uppercase |
LENGTH |
length |
3 Which joins texts?
- AVG
- SUM
- CONCAT Correct answer
- COUNT
Explanation: CONCAT joins texts.