Okay, let's start off. First, we'll need a new operator: ||
(you can type a single |
by pressing shift + '\'
). 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 copywriter;
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.