Link to home
Start Free TrialLog in
Avatar of const71
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?
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Or this:

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.
Avatar of const71
const71

ASKER

Absolutely awesome..Thanks!!