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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:20:15+00:00 2026-05-23T13:20:15+00:00

I have trouble putting together a delete statement in my Android application (I am

  • 0

I have trouble putting together a delete statement in my Android application (I am using OrmLite).

I have a table filled with records. Two of the fields are “dateCreated” (type Date) and “imageSize” (type int). In my code I have a method free(int size). This method tells me that I have to delete oldest records from my table that sum “imageSize” <= size.

For instance .. i get parameter 1000. Each record has value lets say 100. That means i have to delete 10 of the oldest records.

Can some one please provide me with optimal raw SQL statement or even better an OrmLite code for this?

I would be most gratefull.

  • 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-23T13:20:16+00:00Added an answer on May 23, 2026 at 1:20 pm

    Unfortunately, you can’t do this with a single SQL statement. There is no way to say

    select records until their sum is less than X

    You could doing multiple queries until you found the oldest records whose sum is less than X but it would take a number of separate SQL calls.

    I’d recommend selecting the last X images with their sizes and then doing a delete of the right number of images using a DELETE ... IN .... Here’s the pseudo code:

    while (true) {
       SELECT id, imageSize FROM yourtable ORDER BY dateCreated DESC LIMIT 10;
       find the images from the bottom whose sum(imageSize) <= parameter
       delete the found images
       break if you exceed the parameter otherwise loop and get the next 10
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this Caliburn.Micro sample project I'm putting together and I am having trouble
I have trouble using Perl grep() with a string that may contain chars that
I'm putting together a custom SynchronizedCollection<T> class so that I can have a synchronized
I'm new to psuedocode, and I'm having trouble putting all the pieces together: Here
I'm putting together a little game where people are voting to see two other
Ok.. having some real trouble putting two SWF videos into a website for my
I have trouble comparing 2 double in Excel VBA suppose that I have the
I have trouble with the following piece of code. When I go through with
I have trouble defining a trigger for a MySQL database. I want to change
I have no trouble building 1.35.0, as well as 1.36.0 on the timesys arm-gcc

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.