Create Column Conditional On Another Column

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')

Create An If Else Statement

There are a number of ways to do if-else in SQL, my prefered way is the CASE statement.

-- Retrieve all rows
SELECT *,
    -- The case when race = elf, return "Elvish"
    CASE WHEN race = 'Elf' THEN 'Elvish'
         -- When race = human, return "Human"
         WHEN race = 'Human' THEN 'Human'
    -- Call this column "race"
    END AS race
-- Do this from the adventurers table
FROM adventurers
nameageraceweaponrace
Fjoak Doom-Wife28HumanAxeHuman
Alooneric Cortte29ElfBowElvish
Piperel Ramsay35ElfSwordElvish
Casimir Yardley14ElfMagicElvish