sql - Combining and shortening two where clause conditions -
schema:
create table #exclgeokeys (xkey int); insert #exclgeokeys values (1), (2); create table #y (name char(1),xkey int); insert #y values ('a',1), ('c',2), ('d',null), ('e',3), ('f',4);
can shorten following produces same result , doesn't need section or xkey null
?
select * #y xkey not in ( select * #exclgeokeys ) or xkey null;
use option not exists operator
select * #y t not exists ( select 1 #exclgeokeys t2 t.xkey = t2.xkey )
demo on sqlfiddle
option exists , except operators
select * #y t exists ( select t.xkey except select t2.xkey #exclgeokeys t2 )
option not exists , intersect operators
select * #y t not exists ( select t.xkey intersect select t2.xkey #exclgeokeys t2 )