Testing for inequality in T-SQL

前端 未结 4 1025
悲哀的现实
悲哀的现实 2020-11-30 08:49

I\'ve just come across this in a WHERE clause:

AND NOT (t.id = @id)

How does this compare with:

AND t.id != @id
         


        
4条回答
  •  被撕碎了的回忆
    2020-11-30 09:05

    These 3 will get the same exact execution plan

    declare @id varchar(40)
    select @id = '172-32-1176'
    
    select * from authors
    where au_id <> @id
    
    select * from authors
    where au_id != @id
    
    select * from authors
    where not (au_id = @id)
    

    It will also depend on the selectivity of the index itself of course. I always use au_id <> @id myself

提交回复
热议问题