Find numbers that are missing in second table

Rajnilari2015
Posted by Rajnilari2015 under Sql Server category on | Points: 40 | Views : 156
Suppose we have a table

declare @Table1 table(id int)
insert into @Table1
select 1 union all select 2 union all select 3 union all select 4 union all
select 5 union all select 6 union all select 7 union all select 8


And another table as

declare @Table2 table(id int)
insert into @Table2
select 1 union all select 2 union all select 5 union all select 8


We need to find out the numbers that are missing in second table (@Table2)

Solution1:

select id from  @Table1 except select id from  @Table2


Solution2:

select id from  @Table1 where id not in (select id from  @Table2)


Output

id 
3
4
6
7

Comments or Responses

Login to post response