add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
create table tv_shows (
id int,
title varchar(266),
channel varchar(266)
);
create table tv_genres (
id int,
name varchar(266)
);
create table tv_show_genres (
id int,
show_id int,
genre_id int
);
insert into tv_shows values
(1, 'First title', 'NBC'),
(2, 'Second title', 'SomeTVShowChannel'),
(3, 'Some title', 'NBC'),
(4, 'Funny title', 'NBC'),
(5, 'Funny title', 'NBC2');
insert into tv_genres values
(1, 'Comedy'),
(2, 'Detective');
insert into tv_show_genres values
(1, 1, 1),
(2, 2, 2),
(3, 3, 2),
(4, 4, 1),
(5, 5, 2);

Records: 5  Duplicates: 0  Warnings: 0
Records: 2  Duplicates: 0  Warnings: 0
Records: 5  Duplicates: 0  Warnings: 0
SELECT DISTINCT `title`
FROM `tv_shows` AS t
LEFT JOIN `tv_show_genres` AS s ON s.`show_id` = t.`id`
LEFT JOIN `tv_genres` AS g ON g.`id` = s.`genre_id`
WHERE t.`title` NOT IN
(SELECT `title`
FROM `tv_shows` AS t
INNER JOIN `tv_show_genres` AS s ON s.`show_id` = t.`id`
INNER JOIN `tv_genres` AS g ON g.`id` = s.`genre_id`
WHERE g.`name` = "Comedy")
ORDER BY `title`;
title
Second title
Some title
SELECT DISTINCT `title`
FROM `tv_shows` AS t
LEFT JOIN `tv_show_genres` AS s ON s.`show_id` = t.`id`
LEFT JOIN `tv_genres` AS g ON g.`id` = s.`genre_id`
WHERE g.`name` != "Comedy";
title
Second title
Some title
Funny title