Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BETWEEN Versus >= and <= in DB2 SQL Query - Performance

I have the following querys:

SELECT ID, ADDRESS 
FROM EMPLOYEE A 
WHERE ID=12345 
AND CURRENT DATE BETWEEN A.EFF_DT AND A.EXP_DT 

SELECT ID, ADDRESS 
FROM EMPLOYEE A 
WHERE ID=12345 
AND CURRENT DATE >= A.EFF_DT AND CURRENT DATE <= A.EXP_DT 

Out of these two queries which query yields better performance.

Here I am using operators >= and <= instead of BETWEEN.

Please suggest.

Thanks in advance.

like image 399
A Programmer Avatar asked Nov 27 '12 04:11

A Programmer


2 Answers

Both those should give you exactly the same execution profile, based on my knowledge of DB2/z (the LUW product may be different but I doubt it).

If you're really concerned, you should run an EXPLAIN on the two queries to see if there are any differences.

like image 195
paxdiablo Avatar answered Sep 26 '22 01:09

paxdiablo


Between is simply a shorthand for >= and <= ,

if want find more help go to the link is here: Is the 'BETWEEN' function very expensive in SQL Server?

like image 28
Sachin Tanwar - .Net Developer Avatar answered Sep 26 '22 01:09

Sachin Tanwar - .Net Developer