Reputation: 3673
I would like to delete all post
that do not contain a relation to media
.
My select statement looks like this:
select post.*
from post full outer join media m on post.id = m.post_id where m is null;
How would the delete statement look like to delete all entries in the post
table that do not have an entry in media
?
Upvotes: 0
Views: 71
Reputation: 1269445
Use NOT EXISTS
:
delete from post p
where not exists (select 1 from media m where p.id = m.post_id);
Upvotes: 2