Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle query to get Data from table inserted in last 10 mins

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.

like image 911
RBS Avatar asked May 20 '09 20:05

RBS


People also ask

How do I get last 5 minutes data in SQL?

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.

What is the query to fetch last record from the table in Oracle?

Records are not returned in order of anything. and rownum = 1; will get the "last" record. It is the ONLY way.

What is the quickest way to fetch the data from a table in Oracle?

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.


2 Answers

Or slightly more readable:

select *   from mytable  where lastupdatedDate > sysdate - interval '10' minute 
like image 161
Rob van Wijk Avatar answered Sep 27 '22 19:09

Rob van Wijk


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

like image 30
D'Arcy Rittich Avatar answered Sep 27 '22 17:09

D'Arcy Rittich