I am able to fetch values for :
SELECT * FROM table WHERE ATTENDANCE_DATE < SYSDATE;
but no records for
SELECT * FROM table WHERE ATTENDANCE_DATE between SYSDATE and SYSDATE -20;
what is wrong in this?
If you re-write the second where clause to what it means, it's obvious.
The expression between SYSDATE and SYSDATE -20 is equivalent to:
where ATTENDANCE_DATE >= sysdate and ATTENDANCE_DATE <= sysdate - 20;
What you mean is:
where ATTENDANCE_DATE between sysdate - 20 and sysdate;
Theoretically the SQL standard defines the symmetric option for between which allows any "order" of values, so that the following would do what you want:
between symmetric SYSDATE and SYSDATE - 20
But unfortunately Oracle does not support this.
symmetric .
attendance_date?SYSDATEhas a time component, so if you are running the query at 2:00pm,SYSDATE - 20will also be from 2:00pm. Often when checking days you will want to use:WHERE attendance_date BETWEEN TRUNC(SYSDATE - 20) AND TRUNC(SYSDATE)