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                   ) 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -