Compare Values To Subquery

Create Table Of Elves

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

Create Table Of Dwarves

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

Insert Rows Into Elf Table

INSERT INTO elves (name, age, race, weapon)
VALUES ('Dallar Woodfoot', 25, 'Elf', 'Bow'),
       ('Cordin Garner', 29, 'Elf', 'Bow'),
       ('Keat Knigh', 24, 'Elf', 'Sword'),
       ('Colbat Nalor', 124, 'Elf', 'Magic')

Insert Rows Into Dwarf Table

INSERT INTO dwarves (name, age, race, weapon)
VALUES ('Kalog', 23, 'Dwarf', 'Axe'),
       ('Dranar', 145, 'Dwarf', 'Bow'),
       ('Bratar', 12, 'Dwarf', 'Axe'),
       ('Dragga', 23, 'Dwarf', 'Axe')

Check If Each Elf Is Older Than Any Of The Dwarves

-- Retrieve All The Elves
SELECT * FROM elves
-- Where their age is greater than at least one
WHERE age > ANY (
    -- Of all the Dwarves
    SELECT age FROM dwarves
    )
nameageraceweapon
Dallar Woodfoot25ElfBow
Cordin Garner29ElfBow
Keat Knigh24ElfSword
Colbat Nalor124ElfMagic

Check If Each Elf Is Older Than All Of The Dwarves

-- Retrieve All The Elves
SELECT * FROM elves
-- Where their age is greater than all
WHERE age > ALL (
    -- Of all the Dwarves
    SELECT age FROM dwarves
    )