Why use the BETWEEN operator when we can do without it?

前端 未结 11 855
孤独总比滥情好
孤独总比滥情好 2020-12-09 17:31

As seen below the two queries, we find that they both work well. Then I am confused why should we ever use BETWEEN because I have found that BETWEEN behaves differently in d

11条回答
  •  清歌不尽
    2020-12-09 18:09

    I vote @Quassnoi - correctness is a big win.

    I usually find literals more useful than the syntax symbols like <, <=, >, >=, != etc. Yes, we need (better, accurate) results. And at least I get rid of probabilities of mis-interpreting and reverting meanings of the symbols visually. If you use <= and sense logically incorrect output coming from your select query, you may wander some time and only arrive to the conclusion that you did write <= in place of >= [visual mis-interpretation?]. Hope I am clear.

    And aren't we shortening the code (along with making it more higher-level-looking), which means more concise and easy to maintain?

    SELECT * 
    FROM emplyees 
    WHERE salary between 5000 AND 15000; 
    
    
    
    SELECT * 
    FROM emplyees 
    WHERE salary >= 5000 AND salary <= 15000; 
    

    First query uses only 10 words and second uses 12!

提交回复
热议问题