Self Join Table

Create Table Of Adventurers

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

Insert Rows Into Adventurers Table

INSERT INTO adventurers (name, age, child_of)
VALUES ('Dallar Woodfoot', 25, NULL),
       ('Cordin Garner', 29, NULL),
       ('Keat Garner', 24, 'Cordin Garner'),
       ('Colbat Nalor', 124, NULL)

Inner Join Tables

-- Select name of copy1 and name of copy2 (renamed "parent")
SELECT copy1.name, copy2.name as parent
-- Where copy1 and copy2 are identical copies of the adventurers table
FROM adventurers copy1, adventurers copy2
-- Merge copy1 and copy2 where the name of copy1 matches the name of child_of field in copy2
WHERE copy1.name = copy2.child_of
<!DOCTYPE html>
nameparent
Cordin GarnerKeat Garner