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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:31:00+00:00 2026-05-15T05:31:00+00:00

I am trying to delete expired entries in a MySQL database, on creation or

  • 0

I am trying to delete expired entries in a MySQL database, on creation or update a field called lastBeat is updated with CURRENT_TIME and I use the following query to check/delete rows older than 20 seconds:

DELETE * FROM `rmachines` WHERE
 `lastBeat` < (NOW() - 20);

I have also tried CURRENT_TIME instead of NOW()

There are 2 main loops:

  1. Updates a row in rmachines every second

  2. Executes the delete query

If 2 is executed rapidly, as the time rolls over to the next minute (i.e. 59-60 seconds) it deletes the row as if it has expired (even thought it definitely has not!), otherwise it behaves fine.

If 2 executes once a second this is not so noticable, the “false expiry” happens rarely but I run it 5 times per second to expose the ‘issue’.

I found a solution, tested and seems to work under the same scenarios:

a job to delete rows older than 3 months in mysql database

But can anyone tell me why my method does not work?

  • 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-15T05:31:00+00:00Added an answer on May 15, 2026 at 5:31 am

    You are casting NOW() to a number and then subtracting 20 from it. Instead you should subtract 20 seconds using an interval:

    NOW() - interval 20 second
    

    The difference can be seen here:

    SELECT NOW() - interval 20 second, NOW() - 20;
    
    2010-06-11 00:06:49, 20100611000689.000000
                     ^^              ^^
    

    The time 00:06:59 will compare after 00:06:49 but before 000689.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use handle database with insert, update, and delete such as
I am trying to delete some entries in my sqlite database on my iPhone
I am trying to delete all rows from a mysql database where the ID
I am trying to delete several rows from a MySQL 5.0.45 database: delete from
I am trying to delete a list of entries form my table corresponding to
The following doesn't work for firefox. I'm trying delete the table row on click.
I am trying to delete a previously created file called a\ . I tried
I'm trying to delete records that has expired after 20 minutes, the column contains
While trying to delete the data from my SQL Server CE 3.5 database, I
I'm trying to delete a mysql record with javascript but I fail. So this

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.