sql - Get records which are not in tables when passed in In clause? -
i sure title of question need change , not sure put end .
i passing in clause in 2 tables want records not in both tables .
table contains id 1,2 table b contains id 3,4
i passing in in clause (1,2,3,4,5,6)
i looking
1 tablea 2 tablea 3 tableb 4 tableb 5 not found 6 not found
i using union items table , table b not sure how not found records in both table ?
here 1 method. uses exists
check whether tables contain id
:
select id, (case when ina = 1 , inb = 1 'both' when ina = 1 'tablea' when inb = 1 'tableb' else 'not found' end) status (select id, (case when exists (select 1 tablea a.id = ids.id 1 else 0 end) ina, (case when exists (select 1 tableb b b.id = ids.id 1 else 0 end) inb (values (1), (2), (3), (4), (5), (6)) ids(id) ) i;
of course, can add where ina = 0 or inb = 0
if don't want 'both'
rows.