View previous topic :: View next topic
|
Author |
Message |
rakesh17684
New User
Joined: 08 Oct 2006 Posts: 61 Location: San Diego
|
|
|
|
i have a SQL in which i fetch records based on a date range.
i use a 'between' in the where clause of the query. when the start date is greater than the end date in the query i get no rows but vice versa i get the records i want.
why is that ??
SELECT * FROM table1
WHERE date BETWEEN '2008-01-01' and '2008-02-20'; --->
i get the records
SELECT * FROM table1
WHERE date BETWEEN '2008-02-20' and '2008-01-01' ; --->
No records fetched |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
If a date is >= '2008-02-20' it can not be <= '2008-01-01'! |
|
Back to top |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
COL BETWEEN A AND B is equivalent to COL >= A AND COL <= B |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
SELECT * FROM table1
WHERE date BETWEEN '2008-02-20' and '2008-01-01' ; --->
No records fetched
|
The time to be concerned would be if any rows were returned. . . |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
Don't confuse the square root of -1 with SQL, Dick. |
|
Back to top |
|
|
vini_srcna
Active User
Joined: 26 May 2005 Posts: 178 Location: Copenhagen, Denmark
|
|
|
|
Thats how it is defined to work |
|
Back to top |
|
|
chandan.inst
Active User
Joined: 03 Nov 2005 Posts: 275 Location: Mumbai
|
|
|
|
It won't Display any row if you execute the query like
SELECT * FROM table1
WHERE date BETWEEN '2008-02-20' and '2008-01-01'
The generic example using between is like select.... where <col> BETWEEN 1st value and 2nd value
Because for BETWEEN function 1 the 1st value should be low as it selects the only those values whcih satisfies the criteria value >= 1st Value and value =< 2nd value and then fetches the records
In your case there will no such records will come as it will search for dates where Date >= '2008-02-20' and Date =< '2008-01-01'
Reagrds,
Chandan |
|
Back to top |
|
|
|