EDIT : apologizes to Dooh. I just noticed that this answer is essentially a duplicate of the second Dooh request. I will leave it as an executable example.
This can be useful for comparing execution plans for different queries.
declare @table1 as table ( id int, value varchar(10) ) insert into @table1 ( id, value ) values ( 1, 'a' ), ( 1, 'b' ), ( 1, 'c' ), ( 1, 'd' ), ( 2, 'a' ), ( 2, 'c' ), ( 2, 'd' ), ( 3, 'a' ), ( 3, 'b' ), ( 3, 'c' ), ( 3, 'd' ), ( 4, 'a' ), ( 4, 'c' ), ( 4, 'd' ), ( 5, 'a' ), ( 5, 'a' ), ( 5, 'b' ), -- Duplicate 'a's. ( 6, 'a' ), ( 6, 'a' ) -- Duplicate 'a's. select distinct L.id from @table1 as L left outer join @table1 as R on R.id = L.id and R.value = 'b' where R.id is NULL and L.value = 'a'