Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8156659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:01:23+00:00 2026-06-06T17:01:23+00:00

I am collecting data every five minutes and entering it into a MySQL database.

  • 0

I am collecting data every five minutes and entering it into a MySQL database. I would like to extract the most recent row that’s over 2 hours old, followed by over 1 hour old, followed by the most recent row.

I was thinking something along the lines of the following, but I think this will get me the last row of each hour. Meaning if I run the query at 8:05 I might get back rows from 6:57, 7:57 and 8:02, the last 2 of which are much less than an hour apart.

SELECT * 
FROM (
    SELECT * 
    FROM mytable 
    ORDER BY Date DESC 
    GROUP BY HOUR(Date) LIMIT 3
) x 
ORDER BY Date ASC

Thanks for any help or suggestions you can provide.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T17:01:25+00:00Added an answer on June 6, 2026 at 5:01 pm
    SELECT * FROM (
      SELECT * FROM mytable 
      WHERE `Date`<DATE_SUB(NOW(), INTERVAL 2 HOUR) 
      ORDER BY DATE DESC LIMIT 1
    )
    UNION
    SELECT * FROM (
      SELECT * FROM mytable 
      WHERE `Date`<DATE_SUB(NOW(), INTERVAL 1 HOUR) 
      ORDER BY DATE DESC LIMIT 1
    )
    UNION
    SELECT * FROM (
      SELECT * FROM mytable 
      ORDER BY DATE DESC LIMIT 1
    )
    ORDER BY `Date`ASC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a monitoring system that is collecting data every n seconds (n is
I'm collecting data from a system every ~10s (this time difference varies due to
I am loading multiple images into a class instance and I would like to
Are there any .NET frameworks for collecting data similar to Google Analytics, for example
I am developing large data collecting ASP.Net/Windows service application-pair that uses Microsoft SQL Server
I have written an extension method to help with collecting crash data during error
I have a scraper that is collecting some data from elsewhere that I have
Hey folks, every once in a while I have the need to automate data
I have a very small threaded application, which is collecting small chunks of data
I have an application which is supposed to retrieve data from a Website every

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.