Learning machine learning? Try my machine learning flashcards or Machine Learning with Python Cookbook.
Find Values In One Table And Not Another
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')
Find Unique Values In Elves That Aren’t In Dwarves
-- Retrieve all weapons from elves
SELECT weapon FROM elves
-- Find the unique values that are not in...
EXCEPT
-- Retrieve all weapons from dwarves
SELECT weapon FROM dwarves
weapon |
---|
Sword |
Magic |