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 equal to(<=)” operator to search on the date fields. somewhere i also find that we can also use SQL “Between” operator to do the same. just wanted to confirm that is there any difference when we use “Between” operator and when we used “(>= & <=)” operator.
Share
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
BETWEENoperator can be rewritten by Oracle (and MySQL) as twoAND-connected comparisons, and vice versa, ifBETWEENisn’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