I have to get data from Oracle Table in which I have one datefield called lastupdatedDate
and I want to get only that rows back in which lastupdatedDate
is in last 10 mins of sysdate
For example, if in my table I have lastupdateDate
as 05/20/09 4:20:44
then I want this row back in my result if I run the query in between 05/20/09 4:20:44
and 05/20/09 4:30:44
, and not if if I run the query at 05/20/09 5:31:44
.
select * from the_table where timestamp_column <= timestamp '2014-03-25 14:00:00' - interval '5' minute; This assumes that timestamp_column is defined with the data type timestamp . If it isn't you should stop now and re-define your table to use the correct data type.
Records are not returned in order of anything. and rownum = 1; will get the "last" record. It is the ONLY way.
What is the fastest query method to fetch data from the table? Ans: Row can be fetched from table by using ROWID. Using ROW ID is the fastest query method to fetch data from the table.
Or slightly more readable:
select * from mytable where lastupdatedDate > sysdate - interval '10' minute
select * from mytable where lastupdatedDate > sysdate - (10/1440)
A more readable version of this is given by Rob van Wijk here https://stackoverflow.com/a/893668/39430
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With