SQL Server Exists Not Exists dont work with min max Aggregate functions
In my last post, I mentioned how @@ROWCOUNT gets affected when MIN, MAX i.e. aggregate functions are used.
Today, I had similar issues while using EXISTS and NOT EXISTS. I was using NOT EXISTS and records were showing up when really it should have removed the results.
select col1 from tbl1 where not exists (select min(something) from tbl2 where tbl2.col9 = tbl1.col2)
select col1 from tbl1 where not exists (select distinct something from tbl2 where tbl2.col9 = tbl1.col2)
Hope this helps.
Today, I had similar issues while using EXISTS and NOT EXISTS. I was using NOT EXISTS and records were showing up when really it should have removed the results.
select col1 from tbl1 where not exists (select min(something) from tbl2 where tbl2.col9 = tbl1.col2)
select col1 from tbl1 where not exists (select distinct something from tbl2 where tbl2.col9 = tbl1.col2)
Hope this helps.
Comments