Concatenate Values

Note: This code works in PostgreSQL databases, but might not work in other SQL database systems (e.g. MySQL).

Create Table

-- Create table called adventurers
CREATE TABLE adventurers (
    -- string variable
    name varchar(255),
    -- integer variable
    age int,
    -- string variable
    race varchar(255),
    -- string variable
    weapon varchar(255)
)

Insert Rows

-- Insert into the table adventurers
INSERT INTO adventurers (name, age, race, weapon)
VALUES ('Fjoak Doom-Wife', 28, 'Human', 'Axe'),
       ('Alooneric Cortte', 29, 'Elf', 'Bow'),
       ('Piperel Ramsay', 35, 'Elf', 'Sword'),
       ('Casimir Yardley', 14, 'Elf', 'Magic')

Retrieve Two Columns

-- Retrieve name and age values and concatenate together as a sentence
SELECT name||' is '||age||' years old.' FROM adventurers
?column?
Fjoak Doom-Wife is 28 years old.
Alooneric Cortte is 29 years old.
Piperel Ramsay is 35 years old.
Casimir Yardley is 14 years old.