const71
asked on
HOW TO SELECT ROWS WHERE THE TIMESTAMP COLUMN = CURRENT DATE - 1
I need to perform a select and manipulate the where clause like so:
SELECT * FROM MY_TABLE WHERE MY_TIMESTAMP = CURRENT_DATE - 1
the date being at the level of a DAY (not hours or whatever)
anyone know how this is done in Oracle?
SELECT * FROM MY_TABLE WHERE MY_TIMESTAMP = CURRENT_DATE - 1
the date being at the level of a DAY (not hours or whatever)
anyone know how this is done in Oracle?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Absolutely awesome..Thanks!!
SELECT * FROM MY_TABLE WHERE MY_TIMESTAMP between trunc(SYSDATE) - 2 and trunc(SYSDATE) -1;
This can also work, but performance could be terrible:
SELECT * FROM MY_TABLE WHERE trunc(MY_TIMESTAMP) = trunc(SYSDATE - 1);
If the table is large, and if it is indexed on this column, this query will *NOT* be able to use the index, so my first suggestion, or angellll's suggestion will allow index(es) to be used.