SQL where field in vs. where field = with multiple ors?

前端 未结 5 830
-上瘾入骨i
-上瘾入骨i 2021-02-07 09:01

Which of these is better to use in regard to performance? ...in regard to readability / understandability? ...in regard to accepted standards?

SELECT *
FROM Wher         


        
5条回答
  •  盖世英雄少女心
    2021-02-07 09:55

    It more readable, and more universally accepted to do:

    SELECT *
    FROM Wherever
    WHERE Greeting in ('hello', 'hi', 'hey')
    

    All modern SQL servers optimize your queries, so they're both likely to be changed into the same code that runs on the server, so performance differences will be negligible or non-existent.

    Edit:

    Apparently the in option is faster, as it evaluates to a binary lookup, whereas the multiple = just evaulates each statement individually.

提交回复
热议问题