Reputation: 645
I want to fetch data of last 1 hour from mySQL database. I can certainly do it in java after results have been fetched but i don't want to unnecessarily put load on application. Please help.
Upvotes: 1
Views: 1834
Reputation: 1539
select * from yourtable where created_at between NOW() and date_sub(NOW() , interval 1 HOUR)
Upvotes: 0
Reputation: 94429
If the column is of type DATE
you can use the DATE_SUB
function, which substracts a given time interval from a DATE
.
SELECT * FROM [table] WHERE [date_column] > DATE_SUB(NOW(), INTERVAL 1 HOUR)
Upvotes: 0
Reputation: 1394
select * from tb_data
where createdtime > ADDDATE(NOW(), INTERVAL -1 HOUR)
Upvotes: 1