Skip to main content
Tweeted twitter.com/StackDBAs/status/1507915335168671746
edited title
Link
Martin Smith
  • 86.5k
  • 15
  • 252
  • 342

Find non-existent IDs froman IN selectfrom a list that don't exist in a table

Source Link

Find non-existent IDs froman IN select

Say I have the following schema and data:

create table images(
  id int not null
);

insert into images values(1), (2), (3), (4), (6), (8);

I want to perform a query like:

select id from images where id not exists in(4, 5, 6);

But this doesn't work. The case above should return 5, since it doesn't exist in the table records.