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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:40:26+00:00 2026-05-13T13:40:26+00:00

Here is what im trying to do explained in a query DELETE FROM table

  • 0

Here is what im trying to do explained in a query

DELETE FROM table ORDER BY dateRegistered DESC LIMIT 1000 *

I want to run such query in a script which i have already designed. Every time it finds older records that are 1001th record or above it deletes

So kinda of setting Max Row size but deleting all the older records.

Actually is there a way to set that up in the CREATE statement.

Therefore: If i have 9023 rows in the database, when i run that query it should delete 8023 rows and leave me with 1000

  • 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-13T13:40:27+00:00Added an answer on May 13, 2026 at 1:40 pm

    The only way that immediately occurs to me for this exact job is to do it manually.

    First, get a lock on the table. You don’t want the row count changing while you’re doing this. (If a lock is not practical for your app, you’ll have to work out a more clever queuing system rather than using this method.)

    Next, get current row count:

    SELECT count(*) FROM table
    

    Once you have that, you should with simple maths be able to figure out how many rows need deleting. Let’s say it said 1005 – you need to delete 5 rows.

    DELETE FROM table ORDER BY dateRegistered ASC LIMIT 5
    

    Now, unlock the table.


    If a lock isn’t practical for your scenario, you’ll have to be a bit more clever – for example, select the unique ID of all the rows that need deleting, and queue them for gradual deletion. I’ll let you work that out yourself 🙂

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

Sidebar

Ask A Question

Stats

  • Questions 388k
  • Answers 388k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I needed json_encode and json_decode for jquery grid. I tried… May 15, 2026 at 12:32 am
  • Editorial Team
    Editorial Team added an answer The changes that will make deserialization fail are listed in… May 15, 2026 at 12:32 am
  • Editorial Team
    Editorial Team added an answer According to the documentation for the drupal function I think… May 15, 2026 at 12:32 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.