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

  • Home
  • SEARCH
  • 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 807465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:24:10+00:00 2026-05-15T00:24:10+00:00

I have a database with up to some n entries allowed. Periodically, it needs

  • 0

I have a database with up to some n entries allowed. Periodically, it needs to be trimmed down to the most recent m entries.

The table (call it mytable) has a datetime stamp runstamp

My general thought was to run a query like this

delete from mytable where runstamp <
   (select min(runstamp) from mytable order by runstamp limit m)

But it turns out that the max is taken before the limit is applied, and I’m not sure how to get the job done now.

Implementation detail that may not matter: this is being done in sqlite.

  • 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-15T00:24:11+00:00Added an answer on May 15, 2026 at 12:24 am

    A perl-formatted query that solved my issue, sorta based off of blissapp’s link.

       my $truncate_query = "DELETE FROM mytable WHERE runstamp < " .
           "(SELECT MIN(runstamp) FROM " .
           "(SELECT * FROM mytable ORDER BY runstamp DESC LIMIT $max_records))";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an existing database that has some testing data into and I'm interested
I have a database table full of some really ugly and messy data. In
I have inherited a very old database that needs some data to be updated.
I have some entries in my database, in my case Videos with a rating
I have a huge database with some 100 tables and some 250 stored procedures.
I have some data files to import into a database with some unique delimiters:
I have a sql database that stores some documents. A user can sign into
I have a database for a web application that is home to some personal
I have a Linux web server and I'd like to make some database tables
I have a SqlServer database that I've manually filled with some test data. Now

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.