Retrieve Rows Based On Condition

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 Rows Of Elves

-- Retrieve all rows from table
SELECT * FROM adventurers
    -- Where the race is Elf
    WHERE race = 'Elf'
nameageraceweapon
Alooneric Cortte29ElfBow
Piperel Ramsay35ElfSword
Casimir Yardley14ElfMagic

Retrieve Rows Of Non-Elves

-- Retrieve all rows from table
SELECT * FROM adventurers
    -- Where the race is not Elf
    WHERE race <> 'Elf'
nameageraceweapon
Fjoak Doom-Wife28HumanAxe

Retrieve Rows Where Age Is Over 30

-- Retrieve all rows from table
SELECT * FROM adventurers
    -- Where the age is over 30
    WHERE age > 30
nameageraceweapon
Piperel Ramsay35ElfSword

Retrieve Rows Where Age Is Greater Than Or Equal To 20

-- Retrieve all rows from table
SELECT * FROM adventurers
    -- Where the age is greater than or equal to 20
    WHERE age >= 20
nameageraceweapon
Fjoak Doom-Wife28HumanAxe
Alooneric Cortte29ElfBow
Piperel Ramsay35ElfSword