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 6554981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:45:51+00:00 2026-05-25T12:45:51+00:00

How can select the last records added in 5 seconds, 5 minutes, 5 hours,

  • 0

How can select the last records added in 5 seconds, 5 minutes, 5 hours, 5 days, 5 weeks, 5 months, 5 years in one query?

Is it possible to be selected in one query?

sample records include

name | added_timestamp
v | last_five_minutes
k | last_hour
l | last_hour

the timestamps can be pseudo for the actual time

  • 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-05-25T12:45:52+00:00Added an answer on May 25, 2026 at 12:45 pm

    Although you haven’t stated it, I suspect you want totals for the various time periods:

    SELECT
      SUM(date_added > NOW() - INTERVAL 5 SECOND) as total_in_last_5_seconds,
      SUM(date_added > NOW() - INTERVAL 5 MINUTE) as total_in_last_5_minutes,
      SUM(date_added > NOW() - INTERVAL 5 HOUR) as total_in_last_5_hours,
      SUM(date_added > NOW() - INTERVAL 5 DAY) as total_in_last_5_days,
      SUM(date_added > NOW() - INTERVAL 5 WEEK) as total_in_last_5_weeks,
      SUM(date_added > NOW() - INTERVAL 5 MONTH) as total_in_last_5_months,
      SUM(date_added > NOW() - INTERVAL 5 YEAR) as total_in_last_5_years
    from records;
    

    Edited: Added alternative prompted by comment

    If you want the actual records, this will categorize them:

    SELECT
      *,
      case
        when date_added > NOW() - INTERVAL 5 SECOND then 'last_5_seconds'
        when date_added > NOW() - INTERVAL 5 MINUTE then 'last_5_minutes'
        when date_added > NOW() - INTERVAL 5 HOUR then 'last_5_hours'
        when date_added > NOW() - INTERVAL 5 DAY then 'last_5_days'
        when date_added > NOW() - INTERVAL 5 WEEK then 'last_5_weeks'
        when date_added > NOW() - INTERVAL 5 MONTH then 'last_5_months'
        when date_added > NOW() - INTERVAL 5 YEAR then 'last_5_years'
        else 'ancient'
      end as time_category
    from records;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I SELECT the last row in a MySQL table? I'm INSERTING data
How can I combine this two selectors: $(td.listas select:last option:selected) This doesn't work! What
is this good code? can it be simplified somehow? SELECT u.id,u.title,u.title,u.first,u.last FROM (((tblusers u
I would like to ask about the query to select the last record in
How can one get records with highest/smallest per group? Former title of this question
I am querying table to select last n records but preserving the order. For
How can i get the last 100 records from the WADLogsTable Ordered by date
In Sqlite, can I know how to delete last 10 records? I've wrote following
This code can be used to select the first ten records from a table
How can I set a select class and other attributes eg:events through the SelectList

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.