Opposite Of An Inner Join Query Opposite Of An Inner Join Query sql-server sql-server

Opposite Of An Inner Join Query


Select * from table1left join table2 on table1.id = table2.idwhere table2.id is null


This should perform better than the left join...is null version. See here and here for comparisons.

select t1.id, t1.name    from table1 t1    where not exists(select null from table2 t2 where t2.id = t1.id)


Use this query

selectt1.*from table1 t1left outer join table2 t2on t1.id=t2.idwhere t2.id is null

this works by joining everything in t1 to whatever exists in t2. the where clause filters out all of the records that don't exist in t2.