Summer Deals - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Concatenation
4. Concatenation operator ||
Simple text functions
How to modify strings
Review

Instruction

Okay, let's start off. First, we'll need a new operator: || (you can type a single | by pressing ctrl + '\'). These two vertical bars are the concatenation operator, i.e., they join two or more text values (or strings, which is another name for text values). If you write the following:

SELECT first_name || last_name AS name
FROM slogan;

the result for first_name = 'Kate' and last_name = 'Gordon' will be KateGordon, all of this in a single column. Quite simple, right?

Of course we want the first and the last name separated with a space. Here is how you do it:

SELECT first_name || ' ' || last_name AS name
FROM copywriter;

Note that you use apostrophes for specific constant text values (a space in our example: ' '), but you don't use apostrophes for column names (first_name, last_name). The operator || can be used as many times as you need in a single query.

Exercise

Show each copywriter's first_name and last_name in one column separated with a single space. Name the column name.