Delete Rows That Don't Exist In Another Table

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
    alive varchar(255)
)

Create Table Of Alive

-- Create table called alive
CREATE TABLE alive (
    -- string variable
    name varchar(255)
)

Insert Rows Into Elf Table

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

Insert Rows Into Alive Table

INSERT INTO alive (name)
VALUES ('Keat Knigh'),
       ('Colbat Nalor')

Delete Rows In Elf Table That Don’t Exist In Alive Table

-- Delete in elf table
DELETE FROM elves
-- Where the name in elves is not in the list of names in alive.
WHERE elves.name NOT IN (SELECT name FROM alive)

View Elves Table

-- Retrieve all rows from the view Elf
SELECT * FROM elves
nameageracealive
Keat Knigh24ElfYes
Colbat Nalor124ElfYes