Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WHERE IN sql query

Tags:

sql

sql-server

I need to find which items in WHERE IN clause do not exist in the database. in below example cc33 does not exist and I need the query to give back cc33. how would I do that ?

SELECT id FROM tblList WHERE field1 IN ('aa11','bb22','cc33')
like image 987
pirmas naujas Avatar asked Dec 12 '25 07:12

pirmas naujas


1 Answers

You need to put the values into a table rather than a list:

with list as (
    select 'aa11' as val union all
    select 'bb22' union all
    select 'cc33'
)
select l.val
from list l left outer join
     tbllist t 
     on l.val = t.field1
where t.field1 is null
like image 152
Gordon Linoff Avatar answered Dec 13 '25 21:12

Gordon Linoff