sql - Difference between NOT IN and equals vs. IN and not equals -
my query needs return usage records pipeline rate not 'no usage'.
what's difference between not exists vs. not in vs. left join null?
i have seen above question , decided use in on exists values in tables nullable. 1 of following better , more efficient or there other way more efficient following two?
select * usagerecords ur ur.usagerateid not in (select id pipelinerate pr pr.name = 'no usage') select * usagerecords ur ur.usagerateid in (select id pipelinerate pr pr.name <> 'no usage')
not in going give wrong results if id nullable (which hope not, otherwise has terrible name).
why choose in on exists when has been proven time , time again exists more efficient (or @ least no less efficient), since can short-circuit? in has materialize entire set.
select * -- stop doing dbo.usagerecords ur exists ( select 1 dbo.pipelinerate pr pr.id = ur.usagerateid , pr.name <> 'no usage' ); you can express other query this:
select * -- again, stop doing dbo.usagerecords ur not exists ( select 1 dbo.pipelinerate pr pr.id = ur.usagerateid , pr.name = 'no usage' ); but have no idea which, if either, gets correct results. why typically ask sample data , desired results.
your use of select * have greater negative impact on performance whether use in or exists. fwiw.
Comments
Post a Comment