Lessons › SQL › Deep Dive: Text, Date & Number Functions
SQL lesson
Combining columns
Combining columns merges separate text fields into a single unified value.
Try this lesson free →Example
Combining Retail Customer Columns
SELECT customer_id,
first_name || ' ' || last_name AS full_name,
region || ' - ' || channel AS region_channel
FROM customers| customer_id | full_name | region_channel |
|---|---|---|
| C001 | Alice Chen | Northeast - Online |
| C002 | Bob Tanaka | West - In-Store |
| C003 | Carol White | South - Online |
| C004 | David Okafor | Midwest - Mobile |
| C005 | Eva Rossi | Northeast - Online |
Step by step
- AS gives a column a friendlier name in the result.
SELECT customer_id, first_name || ' ' || last_name AS full_name, region || ' - ' || channel AS region_channel - FROM tells SQL which table to pull the data from.
SELECT customer_id, first_name || ' ' || last_name AS full_name, region || ' - ' || channel AS region_channel FROM customers;
Practice
1. Using customers, write a query that joins the customer_id and full_name columns with a space between them.
SELECT customer_id || ' ' || full_name FROM customers2. Using products, write a query that joins the product_id and brand columns with a space between them.
SELECT product_id || ' ' || brand FROM products3. Using suppliers, write a query that joins the supplier_id and supplier_name columns with a space between them.
SELECT supplier_id || ' ' || supplier_name FROM suppliers4. Using employees, write a query that joins the employee_id and full_name columns with a space between them.
SELECT CONCAT(employee_id, ' ', full_name) FROM employees5. Using reviews, write a query that joins the review_id and product_id columns with a space between them.
SELECT review_id || ' ' || product_id FROM reviewsLearn it by doing. This lesson is a short hands-on level on Bampaa: see it work, then build and write it yourself, with instant feedback.
Try this lesson free →