Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I have following where condition in query. What the time is between T1 and T2 means it includes or excludes the boundary. Also between T1 and T1 means what?I am confused as both returns result.

DATETIME BETWEEN TO_DATE(D1-T1,'MM-dd-yyyy HH24:MI:SS' )  AND TO_DATE(D1-T2,'MM-dd-yyyy HH24:MI:SS' )

DATETIME BETWEEN TO_DATE(D1-T1,'MM-dd-yyyy HH24:MI:SS' )  AND TO_DATE(D1-T1,'MM-dd-yyyy HH24:MI:SS' )
share|improve this question
1  
The TO_DATEs make no sense to me, they seem to only introduce implicit type conversion (a bad thing). –  kubanczyk Apr 5 '12 at 9:15
    
@kubanczyk what do you suggest –  kinkajou Apr 6 '12 at 4:37
    
What are the types (definitions) of "DATETIME", "D1", "T1", "T2"? –  kubanczyk Apr 6 '12 at 10:23

1 Answer 1

BETWEEN is inclusive. From the documentation:

And the value of

expr1 BETWEEN expr2 AND expr3

is the value of the boolean expression:

expr2 <= expr1 AND expr1 <= expr3

So your first clause will match exactly T1, exactly T2, and anything in between. Your second clause will match exactly T1, i.e. any rows where DATETIME is exactly T1.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.