Difference in SQL Between operator and “>=” & “<=” operator

后端 未结 3 737
独厮守ぢ
独厮守ぢ 2021-01-13 05:53

We are using a SQL query to search on the basis of dateFrom and dateTo fields. for that i am using \"greater than equal to(>=)\" and \"less than equ

相关标签:
3条回答
  • There is no difference.

    (x BETWEEN y AND z)
    

    is the same as writing

    ((x >= y) AND (x <= z))
    
    0 讨论(0)
  • 2021-01-13 06:06

    Modern databases ship with very intelligent query execution optimisers. One of their main features is query transformation. Logically equivalent expressions can usually be transformed into each other. e.g. as Anthony suggested, the BETWEEN operator can be rewritten by Oracle (and MySQL) as two AND-connected comparisons, and vice versa, if BETWEEN isn't just implemented as syntactic sugar.

    So even if there would be a difference (in performance), you can be assured that Oracle will very likely choose the better option.

    This means that you can freely choose your preference, e.g. because of readability.

    Note: it is not always obvious, what's logically equivalent. Query transformation rules become more complex when it comes to transforming EXISTS, IN, NOT EXISTS, NOT IN... But in this case, they are. For more details read the specification (chapter 8.3 between predicate):

    http://www.contrib.andrew.cmu.edu/~shadow/sql/sql1992.txt

    0 讨论(0)
  • 2021-01-13 06:10

    No as such there is no difference(When using ORACLE) but using BETWEEN operator is more elegant way of comparing values for a range.

    0 讨论(0)
提交回复
热议问题