Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BETWEEN clause versus <= AND >=

Is there a performance difference between using a BETWEEN clause or using <= AND >= comparisons?

i.e. these two queries:

SELECT *     FROM table    WHERE year BETWEEN '2005' AND '2010';   

...and

SELECT *     FROM table    WHERE year >= '2005' AND year <= '2010'; 

In this example, the year column is VARCHAR2(4) with an index on it.

like image 253
wweicker Avatar asked Jan 26 '11 19:01

wweicker


People also ask

Is between faster than greater than less than?

Between is technically greater than and equal to PLUS less than and equal to.

What does >= mean in SQL?

>= (Greater Than or Equal To) (Transact-SQL) - SQL Server | Microsoft Docs.

Which is better and or between in SQL?

From a maintainability perspective, BETWEEN is probably better. The BETWEEN predicate is easier to understand and code than the equivalent combination of the less than or equal to predicate (<=) and the greater than or equal to predicate (>=).

What is the purpose of between clause?

The BETWEEN command is used to select values within a given range. The values can be numbers, text, or dates. The BETWEEN command is inclusive: begin and end values are included.


1 Answers

There is no difference.

Note that BETWEEN is always inclusive and sensitive to the order of the arguments.

BETWEEN '2010' AND '2005' will never be TRUE.

like image 71
Quassnoi Avatar answered Sep 21 '22 01:09

Quassnoi