I am trying to write a query that returns all the strings that are not present in a table when given a list of strings.
When I execute something like:
select *
from public.person
where person_name in ('John', 'Doe', 'Mike')
it will find the person that has the name in the list of strings given, but I want to know the names that are not in the list.
If we have Mike, John, Ben
in public.person
, and I want to pass a list containing
'John', 'Doe', 'Mike'
and I want the query to return
'Doe'
as it is not present.
How can I modify the query to return the Strings present in the list I give and that are not contained in the table?
2
Answers
You can create a table or derived tables with the names you are wanting to feed in, then
LEFT OUTER JOIN
to your table.dbfiddle
You could probably do something like this:
Or you might insert the list into a temp table and do a left join (if null):