clear markdown compare help best fiddles feedback dbanow.uk a leap of faith?
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 2335566 fiddles created (27418 in the last week).

create table story_category(category_id int); create table category (id int); insert into story_category values (1), (2), (3), (4), (5); insert into category values (4), (5), (6), (7);
 hidden batch(es)


SELECT * FROM story_category WHERE category_id NOT IN ( SELECT DISTINCT category.id FROM category INNER JOIN story_category ON category_id=category.id);
category_id
1
2
3
 hidden batch(es)


select sc.* from story_category sc where not exists (select 1 from category c where c.id = sc.category_id)
category_id
1
2
3
 hidden batch(es)


delete from story_category where not exists (select 1 from category c where c.id = story_category.category_id);
 hidden batch(es)


select * from story_category;
category_id
4
5
 hidden batch(es)