SELECT [컬럼 이름]
FROM [테이블 A 이름] AS A
LEFT JOIN [테이블 B 이름] AS B
ON A.[컬럼1 이름] = B.[컬럼1 이름] AND ... AND A.[컬럼N 이름] = B.[컬럼N 이름]
WHERE B.[컬럼 이름] IS NULL;
DROP DATABASE IF EXISTS pokemon; CREATE DATABASE pokemon; USE pokemon; CREATE TABLE mypokemon( number int, name varchar(20), type varchar(20), height float, weight float, attack int, defense int, ); CREATE TABLE friendpokemon( number int, name varchar(20), type varchar(20), height float, weight float, attack int, defense int, ); INSERT INTO mypokemon(number, name, type, attack, defense) VALUES (10,'caterpie', 'bug', 30, 35), (25,'picachu','electric', 55, 40), (27,'raichu','electric', 90, 55), (133,'eevee','normal', 55, 50), (152,'chikoirita','grass', 49, 65); INSERT INTO friendpokemon(number, name, type, attack, defense) VALUES (26,'raichu', 'electric', 80, 60), (125,'electabuzz','electric', 83, 57), (137,'porygon','normal', 60, 70), (153,'bayleef','grass', 62, 80), (172,'pichu','electric', 40, 15), (470,'leafeon','grass', 110, 130);
SELECT distinct type FROM mypoekmon UNION SELECT distinct type FROM friendpokemon;
SELECT number, name FROM mypokemon WHERE type = 'grass' UNION ALL SELECT number, name FROM friendpokemon WHERE type = 'grass';
DROP DATABASE IF EXISTS pokemon; CREATE DATABASE pokemon; USE pokemon; CREATE TABLE mypokemon( number int, name varchar(20), type varchar(20), height float, weight float, attack int, defense int, ); CREATE TABLE friendpokemon( number int, name varchar(20), type varchar(20), height float, weight float, attack int, defense int, ); INSERT INTO mypokemon(number, name, type, attack, defense) VALUES (10,'caterpie', 'bug', 30, 35), (25,'picachu','electric', 55, 40), (27,'raichu','electric', 90, 55), (133,'eevee','normal', 55, 50), (152,'chikoirita','grass', 49, 65); INSERT INTO friendpokemon(number, name, type, attack, defense) VALUES (26,'raichu', 'electric', 80, 60), (125,'electabuzz','electric', 83, 57), (137,'porygon','normal', 60, 70), (153,'bayleef','grass', 62, 80), (172,'pichu','electric', 40, 15), (470,'leafeon','grass', 110, 130);
SELECT mypokemon.name FROM mypokemon INNER JOIN friendpokemon ON mypokemon.number = friendpokemon.number AND mypokemon.name = friendpokemon.name;
SELECT mypokemon.name
FROM mypokemon LEFT JOIN friendpokemon
ON mypokemon.number = friendpokemon.number AND mypokemon.name = friendpokemon.name
WHERE friendpokemon.number IS NULL;