BBampaa

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 →
About 5–10 minutes · no sign-up needed

Example

Combining Retail Customer Columns

SELECT customer_id,
       first_name || ' ' || last_name AS full_name,
       region || ' - ' || channel AS region_channel
FROM customers

Result:

customer_idfull_nameregion_channel
C001Alice ChenNortheast - Online
C002Bob TanakaWest - In-Store
C003Carol WhiteSouth - Online
C004David OkaforMidwest - Mobile
C005Eva RossiNortheast - Online

Step by step

  1. 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
  2. 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

Try each one in your head first, then open the answer.

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 customers
2. Using products, write a query that joins the product_id and brand columns with a space between them.
SELECT product_id || ' ' || brand FROM products
3. 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 suppliers
4. 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 employees
5. 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 reviews

Learn 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 →
About 5–10 minutes · no sign-up needed