create table t1 (id int, email text); insert into t1 values (1, ' abc@gmail.com '), (2, ' xyz@yahoo.com '), (10, ' jhs@gmail.com '), (13, ' cds@gmail.com '), (15, ' gfh@gmail.com '), (20, ' dsf@gmail.com '); create table t2 (id int); insert into t2 values (10), (13), (16), (20), (25), (28), (34), (40), (45); select t2.id from t2 where t2.id not in (select id from t1)
result
16, 25, 28, 34, 40, 45
Demo
UPDATE
if you say
select min(t2.id) from t2 where t2.id not in (select id from t1)
you get only 16 :)
source share